์ ๊ทํํ์์ ๋ฌธ์์ด์์ ํน์ ๋ด์ฉ์ ์ฐพ๊ฑฐ๋ ๋์ฒด ๋๋ ๋ฐ์ทํ๋๋ฐ ์ฌ์ฉํ๋ค.
์ ํจ์ฑ ๊ฒ์ฌ์ ๋ง์ด ์ฐ์ธ๋ค.
๋งํฌ
const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// expected output: 3
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
// expected output: 12
const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
// expected output: "array1:" Array ["one", "two", "three"]
const reversed = array1.reverse();
console.log('reversed:', reversed);
// expected output: "reversed:" Array ["three", "two", "one"]
// Careful: reverse is destructive -- it changes the original array.
console.log('array1:', array1);
// expected output: "array1:" Array ["three", "two", "one"]
let value = 10
let binary = value.toString(2) // "1010"
Number.parseInt(binary, 2) // 10
const sentence = 'The quick brown fox jumps over the lazy dog.';
const index = 4;
console.log(`The character at index ${index} is ${sentence.charAt(index)}`);
// expected output: "The character at index 4 is q"
Math.min()
Math.max()
์ซ์ + ''
Number.isInteger()
function fits(x, y) {
if (Number.isInteger(y / x)) {
return 'Fits!';
}
return 'Does NOT fit!';
}
console.log(fits(5, 10));
// expected output: "Fits!"
console.log(fits(5, 11));
// expected output: "Does NOT fit!"
const array1 = [1, 2, 3, 4];
// fill with 0 from position 2 until position 4
console.log(array1.fill(0, 2, 4));
// expected output: [1, 2, 0, 0]
// fill with 5 from position 1
console.log(array1.fill(5, 1));
// expected output: [1, 5, 5, 5]
console.log(array1.fill(6));
// expected output: [6, 6, 6, 6]
function milliseconds(x) {
if (isNaN(x)) {
return 'Not a Number!';
}
return x * 1000;
}
console.log(milliseconds('100F'));
// expected output: "Not a Number!"
console.log(milliseconds('0.0314E+2'));
// expected output: 3140
const array = [1, 2, 3, 4, 5];
// checks whether an element is even
const even = (element) => element % 2 === 0;
console.log(array.some(even));
// expected output: true
const isBelowThreshold = (currentValue) => currentValue < 40;
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold));
// expected output: true