logo

/Code Snippet|v2.3.2

Module

Static Methods

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

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
var inArray = require('tui-code-snippet/array/inArray'); // node, commonjs

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

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

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
var range = require('tui-code-snippet/array/range'); // node, commonjs

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 23

Zip together multiple lists into a single array.

RETURNS:
{

Array

}
EXAMPLES
var zip = require('tui-code-snippet/array/zip'); // node, commonjs

var 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