ECMAScript 2015功能(数学+数字+字符串+对象API)? [英] ECMAScript 2015 Features (Math + Number + String + Object APIs)?
本文介绍了ECMAScript 2015功能(数学+数字+字符串+对象API)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何才能获得每个数组对象迭代器的值?
我只是有些困惑,任何人都可以帮忙?
let x,y,z; x = [a,b, c]。entries(); console.log(x =+ x); // iterator [0,a],[1,b],[2,c] y = [ a,b,c]。键(); console.log(y =+ y); //迭代器0,1,2z = [a,b,c ] .values(); console.log(z =+ z); //迭代器a,b,c// x = [object Array Iterator] // y = [object Array Iterator] // z = [object Array Iterator] / *如何获取每个数组对象迭代器的值?* /
解决方案
你可以使用 Array.from ()
将迭代器对象转换为数组:
const arr = ['a','b','c'] console .log(Array.from(arr.keys()))
另请参阅MDN上的迭代协议。
How to can I get the value of each array object iterator?
I just have some confused, anybody can help ?
let x, y, z;
x = ["a", "b", "c"].entries();
console.log("x = " + x);
// iterator [0, "a"], [1,"b"], [2,"c"]
y = ["a", "b", "c"].keys();
console.log("y = " + y);
// iterator 0, 1, 2
z = ["a", "b", "c"].values();
console.log("z = " + z);
// iterator "a", "b", "c"
// x = [object Array Iterator]
// y = [object Array Iterator]
// z = [object Array Iterator]
/*
how to can I get the value of each array object iterator?
*/
解决方案
You can use Array.from()
to convert an iterator object to an array:
const arr = ['a', 'b', 'c']
console.log(Array.from(arr.keys()))
See also Iteration protocols on MDN.
这篇关于ECMAScript 2015功能(数学+数字+字符串+对象API)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文