es6语法之find()的基本用法

1064 ℃

今天web建站小编给大家介绍一下关于es6语法find()的基本用法!

方法一:

const arr = [1, 2, 3, 4, 5];
const item = arr.find(function (item) {
  return item > 4;
});
console.log(item);//5

方法二:

const arr = [
{
  id: 1,
  name: '张三',
},
{
  id: 2,
  name: '李四',
},
{
  id: 3,
  name: '王五',
}]

const item = arr.find((item) => item.name === '张三');
console.log(item);
//{id: 1, name: '张三'}

方法三:

const arr = [
{
  id: 1,
  name: '张三',
},
{
  id: 2,
  name: '李四',
},
{
  id: 3,
  name: '王五',
}]

const item = arr.find(function (item) { return item.id >2;});
console.log(item);
//{id: 3, name: '王五'}

方法四:

const arr = [
{
  id: 1,
  name: '张三',
},
{
  id: 2,
  name: '李四',
},
{
  id: 3,
  name: '王五',
}]

const item = arr.find(function (item, index, arr) {
  console.log(item, index, arr);
});
//{id: 1, name: '张三'} 0 (3) [{…}, {…}, {…}]
//{id: 2, name: '李四'} 1 (3) [{…}, {…}, {…}]
//{id: 3, name: '王五'} 2 (3) [{…}, {…}, {…}]

方法五:

const arr = [
{
  id: 1,
  name: '张三',
},
{
  id: 2,
  name: '李四',
},
{
  id: 3,
  name: '王五',
}]

const item = arr.find(function (item, index, arr) {
  console.log(this);
});

filter实现数组过滤,es6语法过滤方法合集

ES6语法中有哪些简单的字符串转数组方法

ES6如何实现模块化编程

ES6语法种有哪些判断方法

vue语法中methods箭头函数的基本用法吗?

标签: es6语法, find

上面是“es6语法之find()的基本用法”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_2589.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

生活小工具

收录了万年历、老黄历、八字智能排盘等100+款小工具!生活小工具
网站的反向链接对于网站优化有多重要
在el-table表头添加icon图标,鼠标经过显示el-tooltip提示内容
js数组基本操作(删除两个数组中相同对象、删除指定对象)
快手PC版
站长在优化时应该如何设置网站的导航栏?