Lodash _.isArrayLike() Method
Lodash _.isArrayLike() method checks if the value is Array-like. A value is considered array-like if it’s not a function and has a value.length that’s an integer greater than or equal to 0 and less than or equal to Number.MAX_SAFE_INTEGER.
Syntax:
_.isArrayLike(value);
Parameter:
- value: This parameter holds the value that needs to be Checked for an Array-Like Value.
Return Value:
This method returns a Boolean value.
Example 1: In this example, the lodash _.isArrayLke() method returns true for an Array.
Javascript
const _ = require( 'lodash' );
let val = [1, 2, 3]
console.log( "The Value is ArrayLike : "
+ _.isArrayLike(val));
|
Output:
The Value is ArrayLike : true
Example 2: In this example, the lodash _.isArrayLke() method returns true for strings as their length can be calculated.
Javascript
const _ = require( 'lodash' );
let val = "GeeksforGeeks" ;
console.log( "The Value is ArrayLike : "
+ _.isArrayLike(val));
|
Output:
The Value is ArrayLike : true
Example 3: In this example, the lodash _.isArrayLke() method returns false.
Javascript
const _ = require( 'lodash' );
let val = { 1: 1 };
console.log( "The Value is ArrayLike : "
+ _.isArrayLike(val));
|
Output:
The Value is ArrayLike : false
Note: This will not work in normal JavaScript because it requires the lodash library to be installed and can be installed using npm install lodash.
Last Updated :
30 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...