Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js add function to array

//create an new function that can be used by any array
Array.prototype.second = function() {
  return this[1];
};

var myArray = ["item1","item2","item3"];
console.log(myArray.second());//returns 'item2'
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #add #function #array
ADD COMMENT
Topic
Name
1+4 =