logo

/Code Snippet|v2.3.2

Module

Static Methods

forEach(obj, iteratee, context)forEach.jsline 44

Execute the provided callback once for each property of object(or element of array) which actually exist.
If the object is Array-like object(ex-arguments object), It needs to transform to Array.(see 'ex2' of example).
If the callback function returns false, the loop will be stopped.
Callback function(iteratee) is invoked with three arguments:
1) The value of the property(or The value of the element)
2) The name of the property(or The index of the element)
3) The object being traversed

PARAMETERS
NameTypeDescription

obj

Object

The object that will be traversed

iteratee

function

Callback function

context

[ Object ]

Context(this) of callback function

EXAMPLES
var forEach = require('tui-code-snippet/collection/forEach'); // node, commonjs

var sum = 0;

forEach([1,2,3], function(value){
    sum += value;
});
alert(sum); // 6

// In case of Array-like object
var array = Array.prototype.slice.call(arrayLike); // change to array
forEach(array, function(value){
    sum += value;
});

forEachArray(arr, iteratee, context)forEachArray.jsline 30

Execute the provided callback once for each element present
in the array(or Array-like object) in ascending order.
If the callback function returns false, the loop will be stopped.
Callback function(iteratee) is invoked with three arguments:
1) The value of the element
2) The index of the element
3) The array(or Array-like object) being traversed

PARAMETERS
NameTypeDescription

arr

ArrayArgumentsNodeList

The array(or Array-like object) that will be traversed

iteratee

function

Callback function

context

[ Object ]

Context(this) of callback function

EXAMPLES
var forEachArray = require('tui-code-snippet/collection/forEachArray'); // node, commonjs

var sum = 0;

forEachArray([1,2,3], function(value){
    sum += value;
});
alert(sum); // 6

forEachOwnProperties(obj, iteratee, context)forEachOwnProperties.jsline 29

Execute the provided callback once for each property of object which actually exist.
If the callback function returns false, the loop will be stopped.
Callback function(iteratee) is invoked with three arguments:
1) The value of the property
2) The name of the property
3) The object being traversed

PARAMETERS
NameTypeDescription

obj

Object

The object that will be traversed

iteratee

function

Callback function

context

[ Object ]

Context(this) of callback function

EXAMPLES
var forEachOwnProperties = require('tui-code-snippet/collection/forEachOwnProperties'); // node, commonjs

var sum = 0;

forEachOwnProperties({a:1,b:2,c:3}, function(value){
    sum += value;
});
alert(sum); // 6

pluck(arr, property)pluck.jsline 32

fetching a property

PARAMETERS
NameTypeDescription

arr

Array

target collection

property

StringNumber

property name

RETURNS:
{

Array

}
EXAMPLES
var pluck = require('tui-code-snippe/collection/pluck'); // node, commonjs

var objArr = [
    {'abc': 1, 'def': 2, 'ghi': 3},
    {'abc': 4, 'def': 5, 'ghi': 6},
    {'abc': 7, 'def': 8, 'ghi': 9}
];
var arr2d = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
pluck(objArr, 'abc'); // [1, 4, 7]
pluck(arr2d, 2); // [3, 6, 9]

toArray(arrayLike)toArray.jsline 31

Transform the Array-like object to Array.
In low IE (below 8), Array.prototype.slice.call is not perfect. So, try-catch statement is used.

PARAMETERS
NameTypeDescription

arrayLike

*

Array-like object

RETURNS:
{

Array

} - Array
EXAMPLES
var toArray = require('tui-code-snippet/collection/toArray'); // node, commonjs

var arrayLike = {
    0: 'one',
    1: 'two',
    2: 'three',
    3: 'four',
    length: 4
};
var result = toArray(arrayLike);

alert(result instanceof Array); // true
alert(result); // one,two,three,four
Resizable