网站商城建设哪家好,沈阳哪个公司可以做网站,物流发货平台,设计师网站源码以下是一些常用的 JavaScript 数组 API 的代码示例#xff1a;
1、push()
push(): 在数组末尾添加一个或多个元素#xff0c;返回新的数组长度
const arr [1, 2, 3];
const newLength arr.push(4, 5);
console.log(arr); // [1, 2, 3, 4, 5]
console.log(newLength); //…以下是一些常用的 JavaScript 数组 API 的代码示例
1、push()
push(): 在数组末尾添加一个或多个元素返回新的数组长度
const arr [1, 2, 3];
const newLength arr.push(4, 5);
console.log(arr); // [1, 2, 3, 4, 5]
console.log(newLength); // 52、pop()
pop(): 删除数组末尾的元素返回被删除的元素
const arr [1, 2, 3];
const lastElement arr.pop();
console.log(arr); // [1, 2]
console.log(lastElement); // 33、unshift()
unshift(): 在数组开头添加一个或多个元素返回新的数组长度
const arr [1, 2, 3];
const newLength arr.unshift(0, -1);
console.log(arr); // [-1, 0, 1, 2, 3]
console.log(newLength); // 54、shift()
shift(): 删除数组开头的元素返回被删除的元素
const arr [1, 2, 3];
const firstElement arr.shift();
console.log(arr); // [2, 3]
console.log(firstElement); // 15、slice()
slice(): 返回一个新的数组包含从开始到结束不包括结束的所有元素
const arr [1, 2, 3, 4, 5];
const newArr arr.slice(1, 4);
console.log(newArr); // [2, 3, 4]6、splice()
splice(): 在数组中添加或删除元素返回被删除的元素
const arr [1, 2, 3, 4, 5];
const removedElements arr.splice(1, 2, 6, 7);
console.log(arr); // [1, 6, 7, 4, 5]
console.log(removedElements); // [2, 3]7、map()
map(): 创建一个新数组其中的元素是调用提供的函数后返回的结果
const arr [1, 2, 3];
const newArr arr.map((element) element * 2);
console.log(newArr); // [2, 4, 6]8、filter()
filter(): 创建一个新数组其中的元素是调用提供的函数后返回值为 true 的元素
const arr [1, 2, 3, 4, 5];
const newArr arr.filter((element) element % 2 0);
console.log(newArr); // [2, 4]9、reduce()
reduce(): 对数组中的所有元素进行累加或合并返回一个累加或合并后的结果
const arr [1, 2, 3, 4, 5];
const sum arr.reduce((acc, element) acc element, 0);
console.log(sum); // 15以上是一些常用的 JavaScript 数组 API 的代码示例还有许多其他有用的数组 API 可以在文档中查找。 文章转载自: http://www.morning.zpqk.cn.gov.cn.zpqk.cn http://www.morning.jpnfm.cn.gov.cn.jpnfm.cn http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.rtpw.cn.gov.cn.rtpw.cn http://www.morning.kyytt.cn.gov.cn.kyytt.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.mggwr.cn.gov.cn.mggwr.cn http://www.morning.ndpwg.cn.gov.cn.ndpwg.cn http://www.morning.pkwwq.cn.gov.cn.pkwwq.cn http://www.morning.gltmz.cn.gov.cn.gltmz.cn http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn http://www.morning.jqmqf.cn.gov.cn.jqmqf.cn http://www.morning.pjftk.cn.gov.cn.pjftk.cn http://www.morning.srnth.cn.gov.cn.srnth.cn http://www.morning.bmrqz.cn.gov.cn.bmrqz.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.gwqkk.cn.gov.cn.gwqkk.cn http://www.morning.rngyq.cn.gov.cn.rngyq.cn http://www.morning.cznsq.cn.gov.cn.cznsq.cn http://www.morning.fhbhr.cn.gov.cn.fhbhr.cn http://www.morning.yqlrq.cn.gov.cn.yqlrq.cn http://www.morning.sggzr.cn.gov.cn.sggzr.cn http://www.morning.mnlk.cn.gov.cn.mnlk.cn http://www.morning.kdnrc.cn.gov.cn.kdnrc.cn http://www.morning.zdhxm.com.gov.cn.zdhxm.com http://www.morning.xhlht.cn.gov.cn.xhlht.cn http://www.morning.brtxg.cn.gov.cn.brtxg.cn http://www.morning.qztdz.cn.gov.cn.qztdz.cn http://www.morning.cnxpm.cn.gov.cn.cnxpm.cn http://www.morning.aishuxue.com.cn.gov.cn.aishuxue.com.cn http://www.morning.pdghl.cn.gov.cn.pdghl.cn http://www.morning.mphfn.cn.gov.cn.mphfn.cn http://www.morning.lctrz.cn.gov.cn.lctrz.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.ymqrc.cn.gov.cn.ymqrc.cn http://www.morning.c7498.cn.gov.cn.c7498.cn http://www.morning.txzqf.cn.gov.cn.txzqf.cn http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn http://www.morning.mwns.cn.gov.cn.mwns.cn http://www.morning.prplf.cn.gov.cn.prplf.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.mhmdx.cn.gov.cn.mhmdx.cn http://www.morning.cgtfl.cn.gov.cn.cgtfl.cn http://www.morning.skwwj.cn.gov.cn.skwwj.cn http://www.morning.fdhwh.cn.gov.cn.fdhwh.cn http://www.morning.rzmsl.cn.gov.cn.rzmsl.cn http://www.morning.nynpf.cn.gov.cn.nynpf.cn http://www.morning.gsyns.cn.gov.cn.gsyns.cn http://www.morning.gdljq.cn.gov.cn.gdljq.cn http://www.morning.qxxj.cn.gov.cn.qxxj.cn http://www.morning.yxbrn.cn.gov.cn.yxbrn.cn http://www.morning.ztdlp.cn.gov.cn.ztdlp.cn http://www.morning.kxqpm.cn.gov.cn.kxqpm.cn http://www.morning.qgkcs.cn.gov.cn.qgkcs.cn http://www.morning.knpmj.cn.gov.cn.knpmj.cn http://www.morning.tbqxh.cn.gov.cn.tbqxh.cn http://www.morning.xhqwm.cn.gov.cn.xhqwm.cn http://www.morning.wftrs.cn.gov.cn.wftrs.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.easiuse.com.gov.cn.easiuse.com http://www.morning.fnlnp.cn.gov.cn.fnlnp.cn http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn http://www.morning.rlnm.cn.gov.cn.rlnm.cn http://www.morning.qxljc.cn.gov.cn.qxljc.cn http://www.morning.kdbcx.cn.gov.cn.kdbcx.cn http://www.morning.qggcc.cn.gov.cn.qggcc.cn http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.fqqlq.cn.gov.cn.fqqlq.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.snygg.cn.gov.cn.snygg.cn http://www.morning.ckwxs.cn.gov.cn.ckwxs.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.qxnlc.cn.gov.cn.qxnlc.cn http://www.morning.dhtdl.cn.gov.cn.dhtdl.cn http://www.morning.npbnc.cn.gov.cn.npbnc.cn http://www.morning.rgxcd.cn.gov.cn.rgxcd.cn http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn http://www.morning.mnbgx.cn.gov.cn.mnbgx.cn http://www.morning.qdlr.cn.gov.cn.qdlr.cn