You are not logged in.
Login
or
Register
.
JsPHP: a JavaScript library providing the PHP API
Home
Register
Demo
Categories
Functions
Contributors
Download
Links
Comments
FAQ
Contact
View
Edit
Benchmark
Revisions
Developers
Dependencies
Talk
Links
current:
Edit: current
Function:
current
View current
Edit current
Edit code
Edit tests
Edit benchmark
View latest code
Edit latest code
Benchmark current
Comment on current
Comment on the latest code
View revisions
View versions
View contributors
View dependencies
View comments
View links
Download production code
Download development code
View the PHP docs
View phpjs.org
View phpjs.org raw code
Description:
Return the element currently pointed to by the internal array pointer.
Edit function
Code
:
function current (arr) { // http://jsphp.co/jsphp/fn/view/current // + original by: Brett Zamir (http://brett-zamir.me) // % note 1: Uses global: php_js to store the array pointer // * example 1: transport = ['foot', 'bike', 'car', 'plane']; // * example 1: current(transport); // * returns 1: 'foot' // BEGIN REDUNDANT this.php_js = this.php_js || {}; this.php_js.pointers = this.php_js.pointers || []; var indexOf = function (value) { for (var i = 0, length = this.length; i < length; i++) { if (this[i] === value) { return i; } } return -1; }; // END REDUNDANT var pointers = this.php_js.pointers; if (!pointers.indexOf) { pointers.indexOf = indexOf; } if (pointers.indexOf(arr) === -1) { pointers.push(arr, 0); } var arrpos = pointers.indexOf(arr); var cursor = pointers[arrpos + 1]; if (Object.prototype.toString.call(arr) === '[object Array]') { return arr[cursor] || false; } var ct = 0; for (var k in arr) { if (ct === cursor) { return arr[k]; } ct++; } return false; // Empty }
You have to be logged in to edit functions.
[
top
]
Comments
There are no comments yet, be the first!
Please
Login
or
Register
to post comments.