我可以在.split()之后直接访问数组的第二个值吗? [英] Can I access directly to the second value of an array after .split()?

查看:107
本文介绍了我可以在.split()之后直接访问数组的第二个值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

var tmp=$(this).attr('id').split("_");

我想在tmp后存储拆分后的第二个值。所以如果$(this).attr('id')=hello_marco我想在tmp中存储值marco,而不是数组。

and I'd like to store on tmp the second value after the split. So if $(this).attr('id') = "hello_marco" I'd like to store in tmp the value marco, not the array.

当然,我想直接在一行代码中完成它,而不先存储数组并使用数组[1]访问它。

Of course, I want to do it directly in one line of code, without first store the array and the access to it with array[1].

是否可以在JS /上Jquery?

Is it possible on JS/Jquery?

推荐答案

var tmp = $(this).attr('id').split("_")[1];

这篇关于我可以在.split()之后直接访问数组的第二个值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆