Skip to content

Instantly share code, notes, and snippets.

@bobdobbalina
Last active May 15, 2020 16:49
Show Gist options
  • Save bobdobbalina/119d829982c87adaa524ad21e0036f8a to your computer and use it in GitHub Desktop.
Save bobdobbalina/119d829982c87adaa524ad21e0036f8a to your computer and use it in GitHub Desktop.
Arrays
{
"scripts": [],
"showConsole": true,
"template": true
}
const prefs = [
{
"Type": "TestType1",
"Key": "key4",
"Value": {
"key": "updated value"
}
},
{
"Type": "FleetOrder",
"Key": "FleetOrder",
"Value": {
"FleetOrder": [
32,
93,
31,
333,
2444,
2575
]
}
},
{
"Type": "TestType1",
"Key": "key3",
"Value": {
"key": "updated value"
}
},
{
"Type": "TestType1",
"Key": "key1",
"Value": {
"key": "Test a new value"
}
}
]
const testTypeObject = prefs.filter( x => x.Type === 'TestType1' );
const testType = testTypeObject[0].Value;
const fleetOrderObject = prefs.filter( x => x.Value.FleetOrder );
const fleetOrder = fleetOrderObject[0].Value;
const userPrefs = { ...fleetOrder, ...testType };
console.dir( JSON.stringify(userPrefs) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment