some returns a boolean value after passing each item in the source array through the test function that you pass in as the first parameter. This makes it well suited to the types of queries that require a simple yes or no answer. In this lesson we look at 2 practical use-cases for some. The first shows how it can be used with a ternary operator to switch a class on an element & the second shows how some can be used in an if conditional.

var tasks = [
{
title: "A",
completed: true
},
{
title: "B",
completed: false
},
{
title: "C",
completed: true
}
]; function addTask(title) {
if(tasks.some( task => task.title === title)){
return ;
} tasks.push({title: title, completed: false});
} addTask('B'); console.log(tasks);

[Javascript] Array methods in depth - some的更多相关文章

  1. [Javascript ] Array methods in depth - sort

    Sort can automatically arrange items in an array. In this lesson we look at the basics including how ...

  2. [Javascript] Array methods in depth - filter

    Array filter creates a new array with all elements that pass the test implemented by the provided fu ...

  3. [Javascript] Array methods in depth - slice

    Array slice creates a shallow copy of an array. In this lesson we cover, in detail, exactly what a ' ...

  4. [Javascript] JavaScript Array Methods in Depth - push

    Array push is used to add elements to the end of an Array. In this lesson we'll see how the push met ...

  5. [Javascript] Array methods in depth - indexOf

    indexOf is used to search for a value or reference inside of an array. In this lesson we first look ...

  6. JavaScript Array methods performance compare

    JavaScript Array methods performance compare JavaScript数组方法的性能对比 env $ node -v # v12.18.0 push vs un ...

  7. javascript Array Methods(学习笔记)

    ECMAScript 5 定义了9个新的数组方法,分别为: 1.forEach();  2.map();  3.filter();  4.every();  5.some();  6.reduce() ...

  8. JavaScript Array 对象

    JavaScript Array 对象 Array 对象 Array 对象用于在变量中存储多个值: var cars = ["Saab", "Volvo", & ...

  9. JavaScript Array(数组)对象

    一,定义数组 数组对象用来在单独的变量名中存储一系列的值. 创建 Array 对象的语法: new Array(); new Array(size); new Array(element0, elem ...

随机推荐

  1. CSS3 过滤

    CSS3 过滤 通过CSS3,我们可以在不适用flash动画或JavaScript的情况下,当元素从一种样式变换为另一种样式时为元素添加效果. 浏览器支持 属性 浏览器支持 transition   ...

  2. How to Install Tomcat

    Read:http://www.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html

  3. How to Build CyanogenMod for One X (codename: endeavoru)

    来源:http://wiki.cyanogenmod.org/w/Build_for_endeavoru#What_you.E2.80.99ll_need How to Build CyanogenM ...

  4. 装饰(Decorator)模式

    1.装饰(Decorator)模式    动态给一个对象添加一些额外的职责.就增加功能来说,装饰模式比生成子类更为灵活.Component是定义一个对象接口.可以给这些对象动态地添加职责.Concre ...

  5. 武汉科技大学ACM:1004: 华科版C语言程序设计教程(第二版)习题5.6

    Problem Description 这天老师又给小豪出了一道题目:给你三根长度分别为a,b,c的火柴,让你计算这三跟火柴能组成的三角形的面积. Input 输入每行包括三个数a,b,c. Outp ...

  6. C/C++安全编码-字符串

    1 字符串     1.1 字符串基础 字符串提供命令行参数.环境变量.控制台输入.文本文件及网络连 接,提供外部输入方法来影响程序的行为和输出,这也是程序容易出错的地方.字符串是一个概念,并不是C/ ...

  7. jquery mobile页面切换效果(Flip toggle switch)(注:jQuery移动使用的数据属性的列表。 )

    1.页面切换(data-transition)

  8. HTML5 canvas中的路径方法

    路径方法 fill()                                填充当前绘图(路径) stroke()                        绘制已定义的路径 begin ...

  9. HTML滚动条

    水平没有滚动条 <body scroll="no" style="overflow-x:hidden"> 垂直没有滚动条 <body scro ...

  10. 一个简单的javascript获取URL参数的代码

    function request(paras){ var url = location.href; var paraString = url.substring(url.indexOf("? ...