🍄🌈🎮💻🚲🥓🎃💀🏴🛻🇺🇸 on Nostr: Say you have a big object but you are just interested in a handful of it's ...
Say you have a big object but you are just interested in a handful of it's properties; you could go:
var {foo, bar} = bigObject;
var smallObject = {foo, bar};
but if there's a lot of properties this could get verbose as you have to keep adding property names twice.
is there "clean" way to do this? like:
var smallObject = ['foo', 'bar'].reduce((_, p) => _[p] = bigObject[p], {} );
#webDev #javaScript #programming
Published at
2024-06-08 04:33:04Event JSON
{
"id": "9b660e9b96900d4bbc3c06d87122345adf0bafcf6c9e15b15c66a0508800aeca",
"pubkey": "9514f8f344dd309396ef36ea9ce44633165c2752c35cb9c52c0144ea8e14a8c0",
"created_at": 1717821184,
"kind": 1,
"tags": [
[
"t",
"programming"
],
[
"t",
"javascript"
],
[
"t",
"webdev"
],
[
"proxy",
"https://mastodon.social/@schizanon/112579129125382404",
"web"
],
[
"proxy",
"https://mastodon.social/users/schizanon/statuses/112579129125382404",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://mastodon.social/users/schizanon/statuses/112579129125382404",
"pink.momostr"
]
],
"content": "Say you have a big object but you are just interested in a handful of it's properties; you could go:\n\nvar {foo, bar} = bigObject;\nvar smallObject = {foo, bar};\n\nbut if there's a lot of properties this could get verbose as you have to keep adding property names twice.\n\nis there \"clean\" way to do this? like:\n\nvar smallObject = ['foo', 'bar'].reduce((_, p) =\u003e _[p] = bigObject[p], {} );\n\n#webDev #javaScript #programming",
"sig": "21f3bc8e8c81cf3389d88f70be8c71a3d746e1beb83aef5abba840f77c67de1f655f0f0e97c875d5990ad0354b881eb2065ade8aa4bcb489c148274a8cdd91a9"
}