Last active
August 9, 2023 12:10
-
-
Save elijahmanor/4759928 to your computer and use it in GitHub Desktop.
jQuery Array-like Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array_like = {}; | |
array_like[ 0 ] = "test 0"; | |
array_like[ 1 ] = "test 1"; | |
array_like[ 2 ] = "test 2"; | |
array_like[ 3 ] = "test 3"; | |
array_like.length = 4; | |
array_like.splice = [].splice; | |
console.log( array_like ); | |
console.log( $.type( array_like ) ); | |
console.log( array_like[ 2 ] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $nodes = $( "div" ), | |
node = $nodes[ 2 ]; | |
console.log( $nodes ); | |
console.log( $.type( $nodes ) ); | |
console.log( node ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... more code ... | |
merge: function( first, second ) { | |
var l = second.length, | |
i = first.length, | |
j = 0; | |
if ( typeof l === "number" ) { | |
for ( ; j < l; j++ ) { | |
first[ i++ ] = second[ j ]; | |
} | |
} else { | |
while ( second[j] !== undefined ) { | |
first[ i++ ] = second[ j++ ]; | |
} | |
} | |
first.length = i; | |
return first; | |
}, | |
// ... more code ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment