How to Use Array Contains String using Node Js?

Jan 12, 2022 . Admin



Hello Friends,

This article will give you example of node js array contains string example. I explained simply about how to use array contains string using node js. This tutorial will give you simple example of use array contains string using node js. This is a short guide on how to use array contains string.

In this post, you'll learn node js array contains string example. i will show you use array contains string using node js.

Here i will give you many example of how to node js array contains string.

Example 1 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

var temp = ["I", "like", "node js"];

isVal = temp.includes('like')

console.log(isVal)

now you can simply run by following command:

node server.js
Output :
true

Example 2 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

const tempStr = {
	list: ["laravel","php","jQuery"]
}
console.log(tempStr.list.includes("node js"))
console.log(tempStr.list.includes("laravel"))

now you can simply run by following command:

node server.js
Output :
false
true

It will help you...

#Node JS