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

162
Views
How to find string value in javascript array of arrays

I'm new to javascript and I'm currently working off a previous question that I'm struggling to understand, where in this one I'm checking for the matching number, but I'd like to check for the string value given. I don't fully understand this below, any help would be appreciatted.

const arr = [["posts",{text: 'hello'}], ["likes", {text: 'liked'}],["comments", {text: 'commented'}]]

const check = 1;

console.log(arr.filter(({ 1: n }) => n === check))

but I'd like to check for a string value, example check = "posts", if possible would you mind explaining as well? Much appreciated

check related question here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can check reference for more info. However what I understood from your question is you are trying to achieve the following:

const arr = [
  ["posts", { text: "hello" }],
  ["likes", { text: "liked" }],
  ["comments", { text: "commented" }],
];
const check = "posts";

console.log(arr.filter((n) => n[0] === check));

Please also explore many other blogs for any functions you get confused in.

about 4 years ago · Juan Pablo Isaza Report

0

I don't know if I understand your question fully, but is this what you're looking for? You simply need to choose first element in each array to compare.

const arr = [["posts",{text: 'hello'}], ["likes", {text: 'liked'}],["comments", {text: 'commented'}]]

console.log(arr.filter(arr => arr[0] === "posts"))
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!