js for 获取对象属性
Posted ax=null
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js for 获取对象属性相关的知识,希望对你有一定的参考价值。
var arr = [‘a‘, ‘b‘, ‘c‘]; // 1 for (var index = 0; index < arr.length; index++) { console.log(arr[index]); } // 2 ES5 arr.forEach(function (value) { console.log(value); }); // 3 for-in work the array or string or other collections that will return an index for (var index in arr) { console.log(arr[index]); } // 4 ES6 for (var value of arr) { console.log(value); } // the for-of also works on strings,set, map var str = "hello boy"; for (var s of str) { console.log(s); } var words = [‘just‘, ‘do‘, ‘it‘, ‘it‘]; var uniqueWords = new Set(words); // console.log(uniqueWords); for (var word of uniqueWords) { console.log(word); } var MyMap = new Map(); for (var index in Map) { }
以上是关于js for 获取对象属性的主要内容,如果未能解决你的问题,请参考以下文章