标签:color 功能 合并 style 数组排序 数组操作 log sort 反转
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘]; let result = list.join(‘ - ‘); console.log(‘old result‘, list) //["a", 12, "c", "d", "e"] console.log(‘new result‘, result) //"a - 12 - c - d - e"
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘]; let result = list.reverse(); console.log(‘old result‘, list) //["e", "d", "c", 12, "a"] console.log(‘new result‘, result) //["e", "d", "c", 12, "a"]
let list = [‘a‘]; let result = list.push(‘b‘,‘c‘); console.log(‘old result‘, list) // ["a", "b", "c"] console.log(‘new result‘, result) //3
let list = [‘a‘,‘b‘]; let result = list.pop(); console.log(‘old result‘, list) // ["a"] console.log(‘new result‘, result) // b
let list = [‘a‘,‘b‘]; let result = list.unshift(‘0‘,‘1‘); console.log(‘old result‘, list) // ["0", "1", "a", "b"] console.log(‘new result‘, result) //4
let list = [‘a‘,‘b‘]; let result = list.shift(); console.log(‘old result‘, list) // ["b"] console.log(‘new result‘, result) // a
let list = [‘a‘,‘b‘,‘c‘,‘d‘,‘e‘]; let result = list.slice(1,2); console.log(‘old result‘, list) // ["a", "b", "c", "d", "e"] console.log(‘new result‘, result) // ["b"]
let list = [‘Jan‘,‘March‘, ‘April‘, ‘June‘]; const result = list.splice(1, 1, ‘Feb‘); console.log(‘old result‘, list) // ["Jan", "Feb", "April", "June"] console.log(‘new result‘, result) // ["March"]
let list = [{ id: 2, msg: ‘老二‘ }, { id: 1, msg: ‘老大‘ }, { id: 4, msg: ‘老四‘ }, { id: 3, msg: ‘老三‘ }]; let result = list.sort((a, b) => { return a.id - b.id; }); console.log(‘old result‘, list) //[{id: 1, msg: "老大"},{id: 2, msg: "老二"},{id: 3, msg: "老三"},{id: 4, msg: "老四"}] console.log(‘new result‘, result) //同上
let list = [‘Jan‘, ‘March‘, ‘April‘, ‘June‘]; const result = list.toString(); console.log(‘old result‘, list) // ["Jan", "March", "April", "June"] console.log(‘new result‘, result) // Jan,March,April,June
let list = [‘Jan‘, ‘March‘, ‘April‘, ‘June‘]; let list2 = [1,2,3] const result = list.concat(list2); console.log(‘old result‘, list) // ["Jan", "March", "April", "June"] console.log(‘new result‘, result) //["Jan", "March", "April", "June", 1, 2, 3]
let list = [[‘飞机‘],[1,2,3,[8,10]]]; const result = list.flat(Infinity); console.log(‘old result‘, list) // 不变 console.log(‘new result‘, result) //["飞机", 1, 2, 3, 8, 10]
<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> <script type="text/javascript"> let lis = document.querySelectorAll(‘li‘); const result = Array.from(lis); console.log(‘old result‘, lis) console.log(‘new result‘, result) </script>
标签:color 功能 合并 style 数组排序 数组操作 log sort 反转
原文地址:https://www.cnblogs.com/liangfc/p/12859193.html