0

I have the following array

data = [
{message:'hello there my name is'},
{message:'this is a test'}
]

I am trying to find an index of this array given a variable like such

const toFind = 'hello there'

Thus the expected return would be an index of [0].

I was looking for something with the effect of IndexOf() or includes(), but I am not sure how to incorporate this into looping the array and finding a substring of the text.

andrew
  • 11
  • 1
  • 1
  • Welcome to SO! Try some of the solutions provided in this answer: https://stackoverflow.com/questions/9907419/how-to-get-a-key-in-a-javascript-object-by-its-value – daveyvdweide Mar 12 '23 at 13:19
  • `const index = data.findIndex(v => v.message.includes(toFind))`, *not listed in closed answer* – Lawrence Cherone Mar 12 '23 at 13:21

0 Answers0