-1

and I want to choose the index where the table is case insensitive

  let table = {'tAble': [{'number': 1}],'CHair': [{'number': 2}]}
   
    console.log(table[/table/i])
    
    
    
Mathew
  • 1

3 Answers3

0

You can do this using Object.keys

table[Object.keys(table).find(x=> /table/i.test(x))]

Here you're getting an array of all keys, and then using find to test them with your RegExp, and then using the found key to retrieve the correct property of the object.

David784
  • 7,031
  • 2
  • 22
  • 29
0
let index = Object.keys(table).findIndex(key => key.toLowerCase() === 'table');
  • 1
    While this code may resolve the OP's issue, it is best to include an explanation as to how your code addresses the OP's issue. In this way, future visitors can learn from your post, and apply it to their own code. SO is not a coding service, but a resource for knowledge. Also, high quality, complete answers are more likely to be upvoted. These features, along with the requirement that all posts are self-contained, are some of the strengths of SO as a platform, that differentiates it from forums. You can edit to add additional info &/or to supplement your explanations with source documentation – ysf Jun 09 '20 at 21:32
0

let table = {'tAble': [{'number': 1}],'CHair': [{'number': 2}]}
   
 let  key = (Object.keys(table).find(i=>i.toLowerCase() === 'table'));
 console.log(key)  
 console.log(table[key])
ABGR
  • 4,631
  • 4
  • 27
  • 49