js中对数组的操作

1、数组中有另一个数组,访问里边数组的数据

let age = [1,2,3,[1,2,3]] age[3][1] //第一个[]是里边的数组的下标,第二个[]是数组中的数据 //2

2、字符串变成数组splict

let name = 'the,first,item,in,the,array' name.splict(",") //通过逗号分隔字符串,变成一个新的数组

3、把数组变成字符串jion()

let age = [1,2,3,'3',1,'2'] age.jion(",")//通过逗号使数组变成字符串

tostring()方法

let name = ['zhang','shuang'] name.tostring() //通过tostring方法使数组变成字符串

4、再数组末尾增加一个项目push()

let myArray = ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']; myArray.push("zhang")

5、删除数组中的最后一个数据pop()

let myArray = ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']; myArray.pop()

6、再数组的第一位增加数据unshift()

let myArray = ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']; myArray.unshift('Edinburgh');

7、删除数组中的第一个数据shift()

let myArray = ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']; myArray.shift();

8、数组过滤filter

let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let res = nums.filter((num) => { return num > 5; }); console.log(res); // [6, 7, 8, 9, 10]

过滤数组

const arr = [ { name: 'tom1', age: 23 }, { name: 'tom2', age: 42 }, { name: 'tom3', age: 17 }, { name: 'tom4', age: 13 }, ] const res = arr.filter(item => item.age > 18); console.log(res); //[{name: 'tom1',age: 23},{name: 'tom2',age: 42}] console.log(arr);

9、数组的拼接concat

var sedan = ["S60", "S90"]; var SUV = ["XC40", "XC60", "XC90"]; var Volvo = sedan.concat(SUV); 结果:"S60", "S90","XC40", "XC60", "XC90"

10、包含includes

arr.includes(6) 数组arr是否包含6

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值