-1

Goal is to see if the the keys in a dictionary are in an array in Javascript.

What would be the best approach for this problem

var fruit_dict = { "apple": 11, "orange": 7, "pineapple": 2, "mango": 12 };

var fruit_list1 = ["apple", "pear", "cherry" "strawberry"];

var fruit_list2 = ["grape", "watermelon", "banana", "blackberry", "blueberry"];

desired output

fruit_list1.includes(fruit_dict.keys())
    true

fruit_list2.includes(fruit_dict.keys())
    false

bombombs
  • 399
  • 11
  • `fruit_dict` is an object. `Array.some()` and `Object.keys()` --> these will help you. `fruitList.some(fruit => Object.keys(fruitObj).includes(fruit));`. It should return `true` for first & `false` for second array. – jsN00b May 06 '22 at 18:12
  • 2
    IMO the *best* way would include writing some code and see if it works, *then* asking specific questions about the code. – Dave Newton May 06 '22 at 18:14

0 Answers0