logo

/Code Snippet|v2.3.3

Module

Static Methods

inArray(searchElement, array, startIndex)inArray.jsline 35

Returns the first index at which a given element can be found in the array
from start index(default 0), or -1 if it is not present.
It compares searchElement to elements of the Array using strict equality
(the same method used by the ===, or triple-equals, operator).

PARAMETERS
NameTypeDescription

searchElement

*

Element to locate in the array

array

Array

Array that will be traversed.

startIndex

number

Start index in array for searching (default 0)

RETURNS:
{

number

} - the First index at which a given element, or -1 if it is not present
EXAMPLES
// ES6
import inArray from 'tui-code-snippet/array/inArray';

// CommonJS
const inArray = require('tui-code-snippet/array/inArray');

const arr = ['one', 'two', 'three', 'four'];
const idx1 = inArray('one', arr, 3); // -1
const idx2 = inArray('one', arr); // 0

range(start, stop, step)range.jsline 28

Generate an integer Array containing an arithmetic progression.

PARAMETERS
NameTypeDescription

start

number

start index

stop

number

stop index

step

number

next visit index = current index + step

RETURNS:
{

Array

}
EXAMPLES
// ES6
import range from 'tui-code-snippet/array/range';

// CommonJS
const range = require('tui-code-snippet/array/range');

range(5); // [0, 1, 2, 3, 4]
range(1, 5); // [1,2,3,4]
range(2, 10, 2); // [2,4,6,8]
range(10, 2, -2); // [10,8,6,4]

zip()zip.jsline 26

Zip together multiple lists into a single array.

RETURNS:
{

Array

}
EXAMPLES
// ES6
import zip from 'tui-code-snippet/array/zip';

// CommonJS
const zip = require('tui-code-snippet/array/zip');

const result = zip([1, 2, 3], ['a', 'b', 'c'], [true, false, true]);
console.log(result[0]); // [1, 'a', true]
console.log(result[1]); // [2, 'b', false]
console.log(result[2]); // [3, 'c', true]
Resizable