JSFiddle - React, Tailwind, and code Playground

by poppin3000

HTML

<body>
</body>

JavaScript

useArray=[];
firstArray=['a','b','c'];
secondArray=['x','y','z'];
var selection = "Name2";

var myObject = [{
      name:"Name1",
      text:"text1",
      array:firstArray
    },{
      name:"Name2",
      text:"text2",
      array:secondArray
    }];

 myObject.forEach(function(item) {
  if (selection === item.name) {
    useArray = item.array
  }
})

console.log(useArray);

$('body').html(JSON.stringify(useArray));