References


some 메서드(Array)(JavaScript)




Source


1. 배열내 모든 요소가 짝수인지 검사하기.


// The callback function.

function CheckIfEven(value, index, ar) {

    if (value % 2 == 0)

        return true;

}


var numbers = [1, 15, 4, 10, 11, 22];


var evens = numbers.some(CheckIfEven);

document.write(evens);


// Output:

// true



2. 기준값을 벗어나는 값이 있는지 검사하기


// Create a function that returns true if the value is 

// outside the range.

var isOutsideRange = function (value) {

    return value < this.minimum || value > this.maximum;

}


// Create an array of numbers.

var numbers = [6, 12, 16, 22, -12];


// The range object is to be the 'this' object.

var range = { minimum: 10, maximum: 20 };


document.write(numbers.some(isOutsideRange, range));


// Output: true

반응형

+ Recent posts