Javascript 在尝试隔离阵列的一部分时遇到困难:(
这是数组Javascript 在尝试隔离阵列的一部分时遇到困难:(,javascript,Javascript,这是数组 [ 'michael@ecorp.com:qnyynf', 'esteban@ecorp.com:uneyrl', 'marquis@ecorp.com:gnlybe', 'denver@ecorp.com:eboreg', 'robin@ecorp.com:zbaxrl', 'royce@ecorp.com:gubznf', 'van@ecorp.com:fgnejnef', 'tony@ecorp.com:cnff', 'thomas@ecorp.c
[ 'michael@ecorp.com:qnyynf',
'esteban@ecorp.com:uneyrl',
'marquis@ecorp.com:gnlybe',
'denver@ecorp.com:eboreg',
'robin@ecorp.com:zbaxrl',
'royce@ecorp.com:gubznf',
'van@ecorp.com:fgnejnef',
'tony@ecorp.com:cnff',
'thomas@ecorp.com:zvpunry',
'dave@ecorp.com:gvttre',
'benjamin@ecorp.com:fhcrezna',
'napoleon@ecorp.com:guhaqre',
'luke@ecorp.com:enatre',
'santos@ecorp.com:zvpuryyr',
'orlando@ecorp.com:npprff',
'wilbur@ecorp.com:cevaprff',
'stan@ecorp.com:cnffjbeq',
'kurtis@ecorp.com:fhafuvar',
'dee@ecorp.com:fhzzre',
'timothy@ecorp.com:wrffvpn' ]
我试图只移动每封用“:”索引的电子邮件的密码,但索引逗号会破坏它。
仍然是一个试图理解这些类型数组的noob
你将如何做到这一点
谢谢您的帮助!您是否尝试过以下方法:
//define array (as you have)
const array = ["1a:1b", "2a:2b", "3a:3b", "4a:4b"];
//map each item within that array. 'item' in this context is any array item. So essentially below is similar to a 'for each' command.
const passwords_001 = array.map(item => {
//I'm splitting each string, using the colon as the marker for 'seperator'
//i.e anything before or after it will be it's own item in the 'itemAsArray' array
var itemAsArray = item.split(':');
//pop() is taking the last item of the relevant array and removing it, but also returning it.
//This can then be passed as an item for the array we are mapping i.e passwords_001
var password = itemAsArray.pop();
//return the password as the new array item
return password;
});
//log the passwords_001 array to see only the passwords returned
console.log(passwords_001);
//console output
//["1b", "2b", "3b", "4b"]
这个
console.log([ 'michael@ecorp.com:qnyynf','esteban@ecorp.com:uneyrl','marquis@ecorp.com:gnlybe','denver@ecorp.com:eboreg','robin@ecorp.com:zbaxrl','royce@ecorp.com:gubznf','van@ecorp.com:fgnejnef','tony@ecorp.com:cnff','thomas@ecorp.com:zvpunry','dave@ecorp.com:gvttre','benjamin@ecorp.com:fhcrezna','napoleon@ecorp.com:guhaqre','luke@ecorp.com:enatre','santos@ecorp.com:zvpuryyr','orlando@ecorp.com:npprff','wilbur@ecorp.com:cevaprff','stan@ecorp.com:cnffjbeq','kurtis@ecorp.com:fhafuvar','dee@ecorp.com:fhzzre','timothy@ecorp.com:wrffvpn']
.map(e=>e.split(“:”)[1]);
您需要更加明确您的目标并更好地展示您的尝试预期的输出是什么?您可以展示一些您尝试过的代码吗?您是否也在尝试将密码移动到单独的数组中?不确定预期的输出是什么,但如果我理解正确,您需要:final=arr.map(el=>el.split)(“:”)[1]);或者[0],如果您只想要电子邮件……老实说,我已经尝试使用concat substring last index等转换为字符串。