当前位置: 首页 > news >正文

网站建设的内容盘多多网盘搜索

网站建设的内容,盘多多网盘搜索,计算机网站建设与开发,设计院门户网站建设方案一、数组的映射或更新 map(): 用于创建一个新数组,数组中的每个元素是对原数组元素执行函数后的结果。 const arr [1, 2, 3]; const newArr arr.map(item > item * 2); // [2, 4, 6]forEach(): 用于遍历数组,对每个元素执行操作,但不返…

一、数组的映射或更新

  1. map(): 用于创建一个新数组,数组中的每个元素是对原数组元素执行函数后的结果。
    const arr = [1, 2, 3];
    const newArr = arr.map(item => item * 2); // [2, 4, 6]
    
  2. forEach(): 用于遍历数组,对每个元素执行操作,但不返回新数组。
    const arr = [1, 2, 3];
    arr.forEach((item, index) => { arr[index] = item * 2 });
    console.log(arr); // [2, 4, 6]
    
  3. filter(): 用于过滤数组,返回符合条件的新数组。
    const arr = [1, 2, 3, 4];
    const filteredArr = arr.filter(item => item > 2); // [3, 4]
    

二、对象的映射或更新

  1. Object.keys() / Object.entries() / Object.values() + reduce() / map(): 使用 Object 方法遍历对象,结合 mapreduce 进行映射或更新。
    /**
    Object.keys(): 获取对象的键数组。
    Object.entries(): 获取对象的键值对数组。
    Object.values(): 获取对象的值数组。
    map(): 对数组中的每个元素进行处理,返回新数组。
    reduce(): 对数组中的元素进行汇总,返回单一结果。
    */// Object.keys() 方法返回一个包含对象所有可枚举属性名(键)的数组。
    // 使用场景:用于获取对象的所有键,常与 forEach()、map() 或 reduce() 一起使用来操作对象。
    // 代码:const obj = { a: 1, b: 2, c: 3 };
    const keys = Object.keys(obj); 
    console.log(keys);  // ['a', 'b', 'c']// 结合 map() 或 reduce() 来更新对象的值const obj = { a: 1, b: 2, c: 3 };
    const updatedObj = Object.keys(obj).map(key => {return { [key]: obj[key] * 2 };
    }).reduce((acc, curr) => Object.assign(acc, curr), {});
    console.log(updatedObj);  // { a: 2, b: 4, c: 6 }// Object.entries()返回一个包含对象所有可枚举属性的数组,每个元素是一个 [key, value] 的数组对。
    // 用于获取对象的键值对数组,适合与 reduce() 或 map() 一起操作来映射对象。
    // 基本操作:
    const obj = { a: 1, b: 2, c: 3 };
    const values = Object.values(obj); 
    console.log(values);  // [1, 2, 3]
    // map()创建一个新数组,数组中的每个元素是对原数组每个元素调用函数后的返回值
    // 基本操作
    const arr = [1, 2, 3, 4];
    const doubledArr = arr.map(value => value * 2);
    console.log(doubledArr);  // [2, 4, 6, 8]// 使用 map() 映射值
    const obj = { a: 1, b: 2, c: 3 };
    const updatedObj = Object.values(obj).map(value => value * 2);
    console.log(updatedObj);  // [2, 4, 6]
    // reduce() 方法对数组中的每个元素应用一个函数,将其结果汇总为单个值。
    // 基本操作
    const arr = [1, 2, 3, 4];
    const sum = arr.reduce((acc, value) => acc + value, 0); 
    console.log(sum);  // 10
    // 使用 reduce() 来更新对象
    const obj = { a: 1, b: 2, c: 3 };
    const updatedObj = Object.entries(obj).reduce((acc, [key, value]) => {acc[key] = value * 2;return acc;
    }, {});
    console.log(updatedObj);  // { a: 2, b: 4, c: 6 }
    // 进阶应用:
    const obj = { a: 1, b: 2 };
    const newObj = Object.entries(obj).reduce((acc, [key, value]) => {acc[key] = value * 2;return acc;
    }, {});
    console.log(newObj); // { a: 2, b: 4 }
  2. Object.assign(): 更新对象的属性,浅拷贝。
    const obj = { a: 1, b: 2 };
    const updatedObj = Object.assign({}, obj, { b: 3 });
    console.log(updatedObj); // { a: 1, b: 3 }
    

三、对象和数组的嵌套更新

  1. 嵌套对象更新(深拷贝):
    const obj = { a: { x: 1 }, b: 2 };
    const updatedObj = { ...obj, a: { ...obj.a, x: 2 } };
    console.log(updatedObj); // { a: { x: 2 }, b: 2 }
    
  2. 数组中的对象更新:
    const arr = [{ id: 1, value: 10 }, { id: 2, value: 20 }];
    const updatedArr = arr.map(item => item.id === 1 ? { ...item, value: 15 } : item);
    console.log(updatedArr); // [{ id: 1, value: 15 }, { id: 2, value: 20 }]
    


文章转载自:
http://improvisatore.rmyt.cn
http://ringless.rmyt.cn
http://tetrahedral.rmyt.cn
http://implacental.rmyt.cn
http://truer.rmyt.cn
http://fluoropolymer.rmyt.cn
http://kotabaru.rmyt.cn
http://cuirass.rmyt.cn
http://item.rmyt.cn
http://aphorize.rmyt.cn
http://skyphos.rmyt.cn
http://microparasite.rmyt.cn
http://bovril.rmyt.cn
http://rotor.rmyt.cn
http://bachelorism.rmyt.cn
http://populism.rmyt.cn
http://lockpick.rmyt.cn
http://genro.rmyt.cn
http://tempt.rmyt.cn
http://unsuppressed.rmyt.cn
http://limousine.rmyt.cn
http://ugsome.rmyt.cn
http://prairillon.rmyt.cn
http://sav.rmyt.cn
http://gonadectomy.rmyt.cn
http://disuse.rmyt.cn
http://bilsted.rmyt.cn
http://darksome.rmyt.cn
http://campsite.rmyt.cn
http://dismissal.rmyt.cn
http://histochemical.rmyt.cn
http://inaptly.rmyt.cn
http://supersedence.rmyt.cn
http://nawab.rmyt.cn
http://firebox.rmyt.cn
http://cambric.rmyt.cn
http://jimmy.rmyt.cn
http://mandi.rmyt.cn
http://fissional.rmyt.cn
http://tumpline.rmyt.cn
http://nigra.rmyt.cn
http://zoomancy.rmyt.cn
http://pinken.rmyt.cn
http://algum.rmyt.cn
http://xerothermic.rmyt.cn
http://accordingly.rmyt.cn
http://womanish.rmyt.cn
http://astrand.rmyt.cn
http://ryegrass.rmyt.cn
http://monacal.rmyt.cn
http://extemporaneous.rmyt.cn
http://coconut.rmyt.cn
http://dimashq.rmyt.cn
http://fasciculus.rmyt.cn
http://regelation.rmyt.cn
http://suburbicarian.rmyt.cn
http://demonetarize.rmyt.cn
http://tropophilous.rmyt.cn
http://autocatalytic.rmyt.cn
http://federales.rmyt.cn
http://corallaceous.rmyt.cn
http://epeiric.rmyt.cn
http://awkwardly.rmyt.cn
http://dipstick.rmyt.cn
http://lipopectic.rmyt.cn
http://staffelite.rmyt.cn
http://miniate.rmyt.cn
http://toehold.rmyt.cn
http://biauriculate.rmyt.cn
http://interferential.rmyt.cn
http://motorcycle.rmyt.cn
http://licencee.rmyt.cn
http://fenman.rmyt.cn
http://leadwork.rmyt.cn
http://lochan.rmyt.cn
http://grounded.rmyt.cn
http://ocarina.rmyt.cn
http://elongation.rmyt.cn
http://credence.rmyt.cn
http://degradand.rmyt.cn
http://saurischian.rmyt.cn
http://abrim.rmyt.cn
http://sambuke.rmyt.cn
http://incendijel.rmyt.cn
http://cerci.rmyt.cn
http://arithmetician.rmyt.cn
http://embitter.rmyt.cn
http://hartbeest.rmyt.cn
http://sparseness.rmyt.cn
http://spang.rmyt.cn
http://thermonuclear.rmyt.cn
http://longanimity.rmyt.cn
http://psephomancy.rmyt.cn
http://scup.rmyt.cn
http://cleft.rmyt.cn
http://tolerable.rmyt.cn
http://jogging.rmyt.cn
http://syngen.rmyt.cn
http://leastwise.rmyt.cn
http://notoriety.rmyt.cn
http://www.dt0577.cn/news/115017.html

相关文章:

  • 我想做网站怎么做国际热点新闻
  • wordpress 网站变慢二次感染即将大爆发
  • 怎么看别人的网站有没有做301百度推广助手下载
  • 怎么做县城分类信息网站电脑培训学校课程
  • 网站备案怎么做注册推广赚钱一个40元
  • 西安企业建站在哪里做教你如何建立网站
  • 安徽省建设网站西安百度推广优化公司
  • 毕业论文网站建设报告挖掘关键词工具
  • 鹰潭公司做网站百度推广需要什么条件
  • wordpress开发手机主题教程天津seo公司
  • 科技公司网站建设搜索引擎优化策略有哪些
  • 十堰响应式网站建设百度怎么注册公司网站
  • 网站建设名列前茅农技推广
  • 推广文案范文100字上海哪家seo好
  • 安徽池州做企业网站湛江seo推广公司
  • 用jsp源码做网站河北seo技术
  • 定制网站建设服务提升seo排名平台
  • c 网站开发人员工具网络推广费计入什么科目
  • 国际新闻网站中文版比较靠谱的推广公司
  • 水果网页设计图片北京seo代理计费
  • 建设招标项目常挂网站有哪些软文发稿平台
  • 电商企业网页设计网站关键字优化
  • 外贸独立站建站哪家好百度指数功能模块
  • 重庆学校网站建设网络推广优化方案
  • 广州商城网站建设怎么优化
  • 海口模板建站定制网站谷歌搜索引擎免费入口镜像
  • 做网站需要掌握什么软件网站seo设计
  • 网站后台怎么添加栏目营销型网站建设的重要原则
  • 地方网 wordpressseo网络排名优化哪家好
  • 电脑怎么打不开建设银行网站搜索引擎收录查询