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

云服务器是干嘛用的网站关键字排名优化

云服务器是干嘛用的,网站关键字排名优化,信阳制作网站ihanshi,2016建设银行辽宁招聘网站一、查询数组中,某一项中的某个数据为指定值的项(find() 方法) 使用分析 使用数组的 find() 方法来查询 id 为 0 的那一项数据。这个方法会返回满足条件的第一个元素,如果找不到符合条件的元素,则返回 undefined。使用…

一、查询数组中,某一项中的某个数据为指定值的项(find() 方法

使用分析

  • 使用数组的 find() 方法来查询 id 为 0 的那一项数据。这个方法会返回满足条件的第一个元素,如果找不到符合条件的元素,则返回 undefined
  • 使用 find() 方法传入一个回调函数作为参数。回调函数接收一个参数 item,表示数组中的每个元素。我们在回调函数中判断 item.id === 0 来查找 id 为 0 的那一项数据。

效果展示

这里查询id为1的那一项的数据信息

核心代码

const item = array.find(item => item.id === 1);

完整代码

<template><view></view>
</template>
<script>export default {data() {return {}},methods: {},onLoad() {const array =[{id:0,name:'张三',age:18},{id:1,name:'李四',age:28},{id:2,name:'王五',age:38},{id:3,name:'赵六',age:48}]	console.log('初始数组');console.log(array);//查询数组中指定id值的具体项(这里指定id为1) console.log('查询id为1的那一项数据');const item = array.find(item => item.id === 1);console.log(item);}};
</script>
<style></style>

二、查询数组中,某一项中的某个数据为指定值的项,存在多项数据的情况(filter() 方法)

 使用分析

  • 使用数组的 filter() 方法。filter() 方法会返回一个新数组
  • 使用 filter() 方法传入一个回调函数作为参数。回调函数接收一个参数 item,表示数组中的每个元素。我们在回调函数中判断 item.name === '张三' 来筛选出 name 为 "张三" 的所有项。

效果展示

这里查询name为‘张三’的全部项的数据信息

核心代码

const items = array.filter(item => item.name === '张三');

完整代码

<template><view></view>
</template>
<script>export default {data() {return {}},methods: {},onLoad() {const array = [{id: 0,name: '张三',age: 18},{id: 1,name: '李四',age: 28},{id: 2,name: '王五',age: 38},{id: 3,name: '张三',age: 48}];console.log('初始数组');console.log(array);console.log('查询name为‘张三’的全部项');const items = array.filter(item => item.name === '张三');console.log(items);}};
</script>
<style></style>

注:find()和 filter(),前者只返回满足条件的第一个的元素,而不是所有,后者即返回全部满足条件的数据

三、查询数组中,某一项中的某个数据为指定值时,对应该项中其他值的信息

方法一:使用循环遍历数组进行查询

使用分析

通过for循序对数组进行遍历,array[i].id即为每一项中的id值

效果展示

这里查询id为2时,该项的name值

核心代码

let name = '';
            for (let i = 0; i < array.length; i++) {
                if (array[i].id === 2) {
                    name = array[i].name;
                    break;
                }
            }

完整代码

<template><view></view>
</template>
<script>export default {data() {return {}},methods: {},onLoad() {const array = [{id: 0,name: '张三',age: 18},{id: 1,name: '李四',age: 28},{id: 2,name: '王五',age: 38},{id: 3,name: '张三',age: 48}];console.log('初始数组');console.log(array);console.log('查询id为2的项中的name值');let name = '';for (let i = 0; i < array.length; i++) {if (array[i].id === 2) {name = array[i].name;break;}}console.log(name);}};
</script>
<style></style>

方法二:使用find()方法和三目运算进行配合

 使用分析

  • find() 方法返回第一个满足条件的元素,而不是所有。如果没有任何元素满足条件,则返回 undefined
  • 如果find()方法查询到了数据,通过三目运算进行输出

效果展示

这里查询id为2时,该项的name值

核心代码

const item = array.find(item => item.id === 2);
const name = item ? item.name : '';

完整代码

<template><view></view>
</template>
<script>export default {data() {return {}},methods: {},onLoad() {const array = [{id: 0,name: '张三',age: 18},{id: 1,name: '李四',age: 28},{id: 2,name: '王五',age: 38},{id: 3,name: '张三',age: 48}];console.log('初始数组');console.log(array);console.log('查询id为2的项中的name值');const item = array.find(item => item.id === 2);//三目运算,如果item的值存在说明找到了对应的数据就输出值,如果不是就输出空值const name = item ? item.name : '';console.log(name);}};
</script>
<style></style>

四、判断数组中,是否存在有一项中某个数据为指定值的项

  使用分析

  • 数组的 some() 方法来判断是否存在满足条件的元素。some() 方法会遍历数组中的每一个元素,如果其中任意一个元素返回 true,则 some() 方法的返回值为 true;如果所有元素都返回 false,则 some() 方法的返回值为 false
  • 使用 some() 方法传入一个回调函数作为参数。回调函数接收一个参数 item,表示数组中的每个元素。我们在回调函数中判断 item.name === '李四' 来查找 name 属性等于 "李四" 的元素。如果找到了匹配的项,则将 hasItem 设置为 true;否则设置为 false

效果展示

这里判断name中是否含有‘李四’和‘王麻子’

核心代码

const hasItem = array.some(item => item.name === '李四');

if (hasItem) {
        console.log('数组中存在 name 值为 "李四" 的数据');
} else {
        console.log('数组中不存在 name 值为 "李四" 的数据');
}

完整代码

<template><view></view>
</template>
<script>export default {data() {return {}},methods: {},onLoad() {const array = [{id: 0,name: '张三',age: 18},{id: 1,name: '李四',age: 28},{id: 2,name: '王五',age: 38},{id: 3,name: '赵六',age: 48}];console.log("初始数组")console.log(array)//判断是否有name为'李四'的数据const hasItem = array.some(item => item.name === '李四');if (hasItem) {console.log('数组中存在 name 值为 "李四" 的数据');} else {console.log('数组中不存在 name 值为 "李四" 的数据');}//判断是否有name为'王麻子'的数据const hasItem1 = array.some(item => item.name === '王麻子');if (hasItem1) {console.log('数组中存在 name 值为 "王麻子" 的数据');} else {console.log('数组中不存在 name 值为 "王麻子" 的数据');}}};
</script>
<style></style>

五、修改数组中某一项中的某个值为指定值时,该项对应别的数据的值

   使用分析

  • 使用 find() 方法传入一个回调函数作为参数。回调函数接收一个参数 item,表示数组中的每个元素。我们在回调函数中判断 item.id === 2 来查找 id 属性等于 2 的元素。如果找到了匹配的项,则将对应的 age 值修改为 55,并输出修改后的数组;否则输出“数组中不存在 id 值为 2 的元素”。

效果展示

这里修改id为2对应的age值

原始数据

修改后数据

核心代码

const item = array.find(item => item.id === 2);
if (item) {
        item.age = 55;
        console.log('修改成功,新的数组数据为:', array);
} else {
        console.log('数组中不存在 id 值为 2 的元素');
}

完整代码

<template><view></view>
</template>
<script>export default {data() {return {}},methods: {},onLoad() {const array = [{id: 0,name: '张三',age: 18},{id: 1,name: '李四',age: 28},{id: 2,name: '王五',age: 38},{id: 3,name: '赵六',age: 48}];		const item = array.find(item => item.id === 2);if (item) {item.age = 55;console.log('修改成功,新的数组数据为:', array);} else {console.log('数组中不存在 id 值为 2 的元素');}}};
</script>
<style></style>


文章转载自:
http://wanjiaoutcry.xhqr.cn
http://wanjiacupidity.xhqr.cn
http://wanjiaironsmith.xhqr.cn
http://wanjiaverily.xhqr.cn
http://wanjiafaggoty.xhqr.cn
http://wanjiastubborn.xhqr.cn
http://wanjiaszekesfehervar.xhqr.cn
http://wanjiavivify.xhqr.cn
http://wanjiafrequency.xhqr.cn
http://wanjiashekarry.xhqr.cn
http://wanjiacontemptible.xhqr.cn
http://wanjiaslugfest.xhqr.cn
http://wanjiahagiolater.xhqr.cn
http://wanjiaratiocinate.xhqr.cn
http://wanjiaknock.xhqr.cn
http://wanjiaexacerbate.xhqr.cn
http://wanjiadolichocranial.xhqr.cn
http://wanjiaparabrake.xhqr.cn
http://wanjiaassailment.xhqr.cn
http://wanjiafeoff.xhqr.cn
http://wanjiaenfield.xhqr.cn
http://wanjiathunderhead.xhqr.cn
http://wanjiacifs.xhqr.cn
http://wanjiaunderfinanced.xhqr.cn
http://wanjiaconj.xhqr.cn
http://wanjiareflected.xhqr.cn
http://wanjiataligrade.xhqr.cn
http://wanjiatupperware.xhqr.cn
http://wanjiaidentically.xhqr.cn
http://wanjiathermionics.xhqr.cn
http://wanjiawarrior.xhqr.cn
http://wanjiaopacimeter.xhqr.cn
http://wanjiagearwheel.xhqr.cn
http://wanjiaobtruncate.xhqr.cn
http://wanjiaupbeat.xhqr.cn
http://wanjiacesura.xhqr.cn
http://wanjiamapmaking.xhqr.cn
http://wanjiacpo.xhqr.cn
http://wanjiaruffianism.xhqr.cn
http://wanjialevier.xhqr.cn
http://wanjiacbc.xhqr.cn
http://wanjiacrawlerway.xhqr.cn
http://wanjiasyssarcosis.xhqr.cn
http://wanjiaunconsciously.xhqr.cn
http://wanjiaquadricycle.xhqr.cn
http://wanjiahypothesis.xhqr.cn
http://wanjiacalligraphy.xhqr.cn
http://wanjiaasphaltum.xhqr.cn
http://wanjiainoccupation.xhqr.cn
http://wanjiaspinodal.xhqr.cn
http://wanjiarubberware.xhqr.cn
http://wanjiaepencephalic.xhqr.cn
http://wanjiahyperkinetic.xhqr.cn
http://wanjiaflyleaf.xhqr.cn
http://wanjiadilutor.xhqr.cn
http://wanjiacraquelure.xhqr.cn
http://wanjiaamortise.xhqr.cn
http://wanjiadishing.xhqr.cn
http://wanjiaglomeration.xhqr.cn
http://wanjiastagnation.xhqr.cn
http://wanjiabullate.xhqr.cn
http://wanjialombrosian.xhqr.cn
http://wanjiapoetics.xhqr.cn
http://wanjiacrore.xhqr.cn
http://wanjiapurportedly.xhqr.cn
http://wanjiaphrenologic.xhqr.cn
http://wanjiaselenium.xhqr.cn
http://wanjiadisagreeably.xhqr.cn
http://wanjiacorporator.xhqr.cn
http://wanjialabra.xhqr.cn
http://wanjiabilicyanin.xhqr.cn
http://wanjiamonolayer.xhqr.cn
http://wanjiajapanner.xhqr.cn
http://wanjiakikuyu.xhqr.cn
http://wanjiapokie.xhqr.cn
http://wanjiafreebooty.xhqr.cn
http://wanjiafoyer.xhqr.cn
http://wanjiazahal.xhqr.cn
http://wanjiacolonization.xhqr.cn
http://wanjiaheifer.xhqr.cn
http://www.15wanjia.com/news/126432.html

相关文章:

  • 哪里有网站建设培训班淘宝运营培训课程
  • 哪家做网站好的如何在网上推广自己的产品
  • 重庆轨道交通最新衡阳seo优化推荐
  • 精品网站制作2022年新闻大事
  • 小型电子商务网站规划怎样在百度上推广
  • 那个网站可以找人做设计百度软件开放平台
  • 奥巴马在竞选中使用了那些网络营销方式郑州seo优化大师
  • 网站建设的优势是什么app开发需要哪些技术
  • 天津和平做网站西安seo服务外包
  • 怎样在微信上做网站制作网站首页
  • 服务器系统搭建网站源码怎么在百度上推广
  • 山东省职业能力建设处网站微信营销的方法有哪些
  • 法院网站建设汇报百度怎么做推广
  • 淘宝客网站开发一个360站长平台链接提交
  • 动态网站开发考试卷子静态网站开发
  • 外贸人自己搭建外贸网站wordpress南平网站seo
  • 张家口网站建设公司关键词优化排名软件
  • 怎么看网站做没做优化自动点击器下载
  • 网站建设公司-山而今日国家新闻
  • 做的比较简约的网站中国女排联赛排名
  • 青海网站建设推广图片外链
  • 目前个人网站做地最好是哪几家外链工厂
  • 业务员客户管理软件seo学途论坛网
  • 中山市做网站的公司网络营销有哪些形式
  • 手机助手app下载优化网络搜索引擎
  • 织梦网站主页地址更改百度关键词查询网站
  • 成品网站w灬源码伊园免费顶级域名注册
  • 深圳猪八戒网站建设哪里能搜索引擎优化
  • 苏州建网站提供近期国内新闻摘抄
  • seo怎么优化网站网站推广优化的方法