JavaScript 数组 002

    xiaoxiao2021-04-18  53

    -------------------------------------------------------------------------------------------- var box = [2,6,18,17,12]; alert(box.reverse()); //作用:按照已有的顺序,逆向输出, 直接修改数组 function show (a,b) { return a-b; } //作用:定义一个方法传给sort,以便于从小到大输出。 加上.reverse后,就逆序,从大到小输出 var box = [2,6,18,17,12]; //直接修改数组 alert(box.sort(show).reverse()); var box = [1,2,3]; var box2 = [7,8,9] alert(box.concat(box2)); //作用:将两个数组 连接起来,不改变原数组 alert(box); var box = [1,2,3,4]; alert(box.concat(78)); //作用:在数组末尾添加元素 不直接修改数组,而是返回副本 alert(box);
    转载请注明原文地址: https://ju.6miu.com/read-675248.html

    最新回复(0)