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

280
Views
Can I get all elements of an array as separate strings?

Like the title says, I want to get every element of an array as its own string in order to check if a certain other array includes any of the strings from array 1.

I feel like I've been trying at this forever and I'm not sure if it's even possible but I could just be stupid. Any help would be greatly appreciated!

const v = items.map((value) => {
        if(value.tags.includes('weapon')) return value.id
})
const results = v.filter(e => {
    return e !== undefined
})
const c = Object.keys((challengerItems)).map((key) => {return key})
const o = Object.keys((opposerItems)).map((key) => {return key})

const va = results.filter(element => {
    return element
});

if(challengerItems === undefined) return message.reply(`\`❓\` <@${message.author.id}> does not have any weapons! Duel canceled!`)
if(opposerItems === undefined) return message.reply(`\`❓\` <@${opposer.id}> does not have any weapons! Duel canceled!`)

if(!c.includes(CHECK IF USER HAS ANY WEAPONS)) return message.reply(`\`❓\` <@${message.author.id}> does not have any weapons! Duel canceled!`) 
if(!o.includes(CHECK IF OTHER USER HAS ANY WEAPONS)) return message.reply(`\`❓\` <@${opposer.id}> does not have any weapons! Duel canceled!`) 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use map to convert every element to string (I used toString() one could JSON.stringify if that suits)

Use find and indexOf to locate items from array 2 that are included in array 1

var arr1 = [2, 17, 'B'];

var arr2 = ["18", "17", "dog"];

// convert arr1 elements to string
arr1 = arr1.map(item => item.toString())

console.log(arr2.find(item => arr1.indexOf(item) > -1))

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!