About: Array.indexOf and Array.lastIndexOf Methods   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : dbkwik.org associated with source dataset(s)

The following code sample adds indexOf and lastIndexOf methods to the standard Array object. Just add this section of code anywhere in your script and you will be able to call the methods on any Array you create. Usage:

AttributesValues
rdfs:label
  • Array.indexOf and Array.lastIndexOf Methods
rdfs:comment
  • The following code sample adds indexOf and lastIndexOf methods to the standard Array object. Just add this section of code anywhere in your script and you will be able to call the methods on any Array you create. Usage:
dcterms:subject
abstract
  • The following code sample adds indexOf and lastIndexOf methods to the standard Array object. Just add this section of code anywhere in your script and you will be able to call the methods on any Array you create. Usage: var myArray = new Array('a','b','c','b','d'); log(myArray.indexOf('c')); //Returns 2 log(myArray.indexOf('c', 3)); //Returns -1 log(myArray.lastIndexOf('b'); //Returns 3 log(myArray.lastIndexOf('c', 3)); //Returns -1 /* Provides a method of searching for a specified value in an Array. Returns the index of the first matching element or -1 if the element is not found */ if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(item, startIndex) { var len = this.length; if (startIndex == null) startIndex = 0; else if (startIndex < 0) { startIndex += len; if (startIndex < 0) startIndex = 0; } for (var i = startIndex; i < len; ++i) { var val = this[i] || this.charAt && this.charAt(i); if (val === item) return i; } return -1; }; } /* Provides a method of searching for a specified value in an Array. Returns the index of the last matching element or -1 if the element is not found */ if (!Array.prototype.lastIndexOf) { Array.prototype.lastIndexOf = function(item, startIndex) { var len = this.length; if (startIndex == null || startIndex >= len) startIndex = len - 1; else if (startIndex < 0) startIndex += len; for (var i = startIndex; i >= 0; --i) { var val = this[i] || this.charAt && this.charAt(i); if (val === item) return i; } return -1; }; }
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software