Wednesday, July 8, 2026
HomeLanguagesJavascriptUnderscore.js _.isAssociative() Method

Underscore.js _.isAssociative() Method

The _.isAssociative() Method checks whether the given value is associative or not. An associative object is one in which its elements can be accessed via a key or index. Exp, Arrays.

Syntax:

_.isAssociative(value);

Parameters: This method accepts a single parameter as mentioned above and described below:

  • value: Given value to be checked for associative.

Return Value: This method returns a Boolean value(Returns true if the given value is associative, else false).

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. 

underscore.js contrib library can be installed using:

npm install underscore-contrib

Example 1: Method returning true for an array.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Associative : " + _.isAssociative([1, 2, 3, 4]));


Output:

The Value is Associative : true

Example 2: Method returning false for an integer.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Associative : " + _.isAssociative(2));


Output:

The Value is Associative : false

Example 3: For a mapping, this method returns true as its value can be accessed by keys.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Associative : " +_.isAssociative({1:2, 3:3}));


Output:

The Value is Associative : true

Example 4: Method returning false for a string variable.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Associative : " +_.isAssociative("neveropen"));


Output:

The Value is Associative : false
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12016 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS