JS 将数字字符串数组转为 数字数组 (互换)
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.map(String); //结果: ['1', '2', '3', '4', '5', '6', '7', '8', '9'] var a = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] a.map(Number); //结果:[1, 2, 3, 4, 5, 6, 7, 8, 9]
js获取 数组对象中 某一个key的值组成的数组
let arr= [ {age:13,name:"a"}, {age:14,name:""}, {age:15,name:"c"}, {age:16,name:"d"}, {age:16,name:"e"}, ] let nameArr = arr.map(item => item.name); console.log(nameArr);//["a", "", "c", "d", "e"]
js判断一个数组是否包含另一个数组(一维数组)
let a= [1,2,3,4]; let b = [1,2,3] let result = b.every(item => (a.includes(item)));//b的所有值 是否包含于a console.log(result);//true let result2 = a.every(item => (b.includes(item)));//a的所有值 是否包含于b console.log(result2);//false
。