Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
How can check string value that contain in main string value in array by javascript

I want to check user.uid that contain or not in combined user ids. here is combined ids in arrays

getid Array [
  "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2",
  "KgRwTDgenjYpODPxRaldDQy9nnH36Lf5bHwzCSbI2bmoMv7KuduMGwe2",
  "pNv0iKlZ6xVOl0fFOZSoXJoPuVx2E8R52y6dD8XI3shXhnhS9pVzUpe2",
]

here is user.uid

pNv0iKlZ6xVOl0fFOZSoXJoPuVx2

I want to get result is my user.uid is in or not in this combined Id arrays.

const uid = user.uid in getId ? yes : no 

(or ) how can check this condition .I not know. I not want to remove my user.uid from combined id , I just want to check my user.uid is in or not in this combined Id. can someone help me?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can simply check using array functions like filter, find , findIndex, some

let array = [
  "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2",
  "KgRwTDgenjYpODPxRaldDQy9nnH36Lf5bHwzCSbI2bmoMv7KuduMGwe2",
  "pNv0iKlZ6xVOl0fFOZSoXJoPuVx2E8R52y6dD8XI3shXhnhS9pVzUpe2",
];

let userId = 'pNv0iKlZ6xVOl0fFOZSoXJoPuVx2';

const exist = array.filter(id => id.includes(userId)).length > 0;

//Using some method

const exist1 = array.some(id => id.includes(userId));

console.log(exist, exist1);

about 4 years ago · Santiago Trujillo Report

0

If you just want to get a boolean value indicating if element is in the array or not, you can simply use getId.includes(user.uid). Check out this MDN link if want to know more about Array.prototype.includes()

const arr = [  "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2",  "KgRwTDgenjYpODPxRaldDQy9nnH36Lf5bHwzCSbI2bmoMv7KuduMGwe2",  "pNv0iKlZ6xVOl0fFOZSoXJoPuVx2E8R52y6dD8XI3shXhnhS9pVzUpe2",
]

const invalidId = 'pNv0iKlZ6xVOl0fFOZSoXJoPuVx2'
const validId = "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2"

const arrayHasInvalidId = arr.includes(invalidId)
const arrayHasValidId = arr.includes(validId)


console.log(arrayHasInvalidId,arrayHasValidId);

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!