• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

267
Views
Difference between in and includes in NodeJS

I was very surprised to find out that:

> 'a' in ['a', 'b']
false
> ['a','b'].includes('a')
true

What does each command perform in NodeJS?

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This is not node specific but ECMA (JS) specific.

in Operator

Checks the existence of key in the collection (similar to hasOwnPropertybut also check inherited keys in prototype chain)

includes method of Array (introduced in ES6)

Checks the existence of value in the collection

almost 3 years ago · Juan Pablo Isaza Report

0

Array.includes() checks for the existence of a certain value in an array, while the in operator checks for the existence of a key in an object (or an index in the case of arrays like you're describing).

console.log('a' in ['a', 'b']); // false, no such key
console.log(0 in ['a', 'b']); // true, 0 is a key that exists
console.log(1 in ['a', 'b']); // true, 1 is a key that exists
console.log(2 in ['a', 'b']); // false, 2 is a key that doesn't exists

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error