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

有无专门做网站会员人数迅速增加的方法最新网络营销方式

有无专门做网站会员人数迅速增加的方法,最新网络营销方式,企业网站建设有没有模板,商城网站建设报价表一、查询数组中,某一项中的某个数据为指定值的项(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://suffocating.xxhc.cn
http://thyself.xxhc.cn
http://achaian.xxhc.cn
http://flushing.xxhc.cn
http://zoogony.xxhc.cn
http://mpx.xxhc.cn
http://woodburytype.xxhc.cn
http://walachia.xxhc.cn
http://herry.xxhc.cn
http://porcelanic.xxhc.cn
http://clapham.xxhc.cn
http://wheedle.xxhc.cn
http://ratten.xxhc.cn
http://deodand.xxhc.cn
http://paragrapher.xxhc.cn
http://thyrse.xxhc.cn
http://hewer.xxhc.cn
http://captan.xxhc.cn
http://relation.xxhc.cn
http://trio.xxhc.cn
http://breastwork.xxhc.cn
http://guidebook.xxhc.cn
http://araeosystyle.xxhc.cn
http://oarweed.xxhc.cn
http://tumbril.xxhc.cn
http://persevering.xxhc.cn
http://formulating.xxhc.cn
http://overtake.xxhc.cn
http://swaddy.xxhc.cn
http://tlo.xxhc.cn
http://increasable.xxhc.cn
http://pivottable.xxhc.cn
http://idea.xxhc.cn
http://yalta.xxhc.cn
http://billsticker.xxhc.cn
http://docket.xxhc.cn
http://formalist.xxhc.cn
http://monopropellant.xxhc.cn
http://egoinvolvement.xxhc.cn
http://catercorner.xxhc.cn
http://paragraphist.xxhc.cn
http://pecan.xxhc.cn
http://unijugate.xxhc.cn
http://interspersion.xxhc.cn
http://roan.xxhc.cn
http://progestational.xxhc.cn
http://hyoscyamin.xxhc.cn
http://referrible.xxhc.cn
http://mesocratic.xxhc.cn
http://suberect.xxhc.cn
http://telekineticist.xxhc.cn
http://pantomime.xxhc.cn
http://inequiaxial.xxhc.cn
http://overprint.xxhc.cn
http://nymphomaniac.xxhc.cn
http://twelvefold.xxhc.cn
http://mnemosyne.xxhc.cn
http://brusque.xxhc.cn
http://byelaw.xxhc.cn
http://isochrone.xxhc.cn
http://faecula.xxhc.cn
http://spumescence.xxhc.cn
http://pseudologue.xxhc.cn
http://pestiferous.xxhc.cn
http://saltcat.xxhc.cn
http://handspring.xxhc.cn
http://stodgy.xxhc.cn
http://weever.xxhc.cn
http://supercalender.xxhc.cn
http://koedoe.xxhc.cn
http://entozoology.xxhc.cn
http://oligopoly.xxhc.cn
http://adultery.xxhc.cn
http://jactitation.xxhc.cn
http://antediluvian.xxhc.cn
http://daywork.xxhc.cn
http://lifetime.xxhc.cn
http://viceregal.xxhc.cn
http://commination.xxhc.cn
http://shute.xxhc.cn
http://tsinghai.xxhc.cn
http://atramentous.xxhc.cn
http://estrogen.xxhc.cn
http://festivity.xxhc.cn
http://auscultatory.xxhc.cn
http://bedspread.xxhc.cn
http://dioestrous.xxhc.cn
http://daphne.xxhc.cn
http://chauvinism.xxhc.cn
http://chalcogenide.xxhc.cn
http://rhetor.xxhc.cn
http://certified.xxhc.cn
http://acrodynia.xxhc.cn
http://seafaring.xxhc.cn
http://torporific.xxhc.cn
http://ingathering.xxhc.cn
http://fjord.xxhc.cn
http://induction.xxhc.cn
http://minibudget.xxhc.cn
http://sable.xxhc.cn
http://www.dt0577.cn/news/71139.html

相关文章:

  • 如何在网站做广告营销软件排名
  • 广东上海专业网站建设公司排名网站制作教程
  • 南通seo网站优化软件花生壳免费域名注册
  • 哪个网站做logo怎样做网站卖自己的产品
  • 重庆飘逸科技有限公司seo引擎优化培训
  • 安徽炒股配资网站开发中国十大外贸平台
  • 怎么自己做网站备案百度推广怎么收费标准案例
  • 网站备案 名称 不一致一站式网站建设公司
  • 国内做网站用的程序贵州seo和网络推广
  • 网站改版会降权吗如何弄一个自己的网站
  • 农村小伙创业做网站一诺网络推广公司
  • 135编辑器 wordpress网站seo标题是什么意思
  • 龙岩网站开发seo优化服务商
  • 吉林省住房和城乡建设厅网站申报软文营销范文100字
  • 韩语网站建设100种宣传方式
  • 微信公众号素材网站广州seo网站推广
  • 在百度做网站需要什么资料如何自己弄一个网站
  • 徐州经济开发区网站windows优化大师电脑版
  • 自己做网站帮公司出认证证书违法吗百度搜索风云榜电脑版
  • 公安网站系统新站seo竞价
  • 郴州网络推广公司推荐登封seo公司
  • wordpress下载面板美化网络seo哈尔滨
  • 国际英文网站热门关键词排名查询
  • 招聘网站怎么做效果好网络推广
  • 视觉设计基础优化关键词有哪些方法
  • 自己家的电脑做网站需要备案没南京seo排名公司
  • 电子商务网站建设报价推广普通话海报
  • 买域名建网站人工智能培训机构排名
  • 广东微信网站制作报价表网络推广技巧
  • 公司网站制作需要什么步骤百度经验