Difference between revisions of "Useful Functions"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
== Map function == | == Map function == | ||
''' will duplicate an array to another'' | ''' will duplicate an array to another'''<br> | ||
''' This will retrieve the ages of everyone 18 or over and add them to the array full | |||
<pre> | |||
var ages[12, 13, 16, 21] | |||
var full = ages.map(function(curr){ | |||
return cur >=18; | |||
}) | |||
''' This will get the 'true' boolean value of ages>= 18 then we have to use the indexOf to find the element position | |||
console.log(ages[full.indexOf(true)]); | |||
</pre> | |||
== Splice == | == Splice == |
Revision as of 15:20, 2 December 2016
Map function
will duplicate an array to another
This will retrieve the ages of everyone 18 or over and add them to the array full
var ages[12, 13, 16, 21] var full = ages.map(function(curr){ return cur >=18; }) ''' This will get the 'true' boolean value of ages>= 18 then we have to use the indexOf to find the element position console.log(ages[full.indexOf(true)]);
Splice
indexOf
Split
Used to split text given a delimiter into an array of substrings
var myText = 'hello-1' var mysplit = myText.split('-')
Will Yield
['hello', 1]