首页 > 代码库 > js for 获取对象属性
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 获取对象属性
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。