Linked Questions
56 questions linked to/from How to conditionally add a member to an object?
1
vote
0
answers
253
views
javascript conditional object literal properties? [duplicate]
Here is some source code from jquery, namely from the function jQuery.speed that deals with animations:
jQuery.speed = function( speed, easing, fn ) {
var opt = speed && typeof speed === "...
0
votes
1
answer
179
views
Omit object's key-value if value == null [duplicate]
Having typescript code presented below, which creates new record in the Firestore database, is it possible to omit (by writing one line of inline code) one of the key-value pair if the value equals ...
0
votes
1
answer
80
views
If statement within return [duplicate]
How do I add an if statement in a return statement of this sort:
return {
ID: select('core/editor').getEditedPostAttribute('featured_media'),
if (ID) {
media: select('core').getMedia( ...
1
vote
4
answers
90
views
How do I selectively define/declare keys for an objects in JavaScript? [duplicate]
Given an Object s as
s = {
a:1,
b:2
}
I can define a new object t with fields depending on the contents of s,
say something like
t = {
d: s.a ? 1 : 2
}
then the field d value depends on ...
0
votes
0
answers
161
views
Javascript optional key in an object [duplicate]
I have looked for an answer to this and Haven't quite been able to find it. Is it possible to have an object that includes/excludes keys dynamically?
Consider these two examples:
Example 1
const ...
0
votes
2
answers
105
views
Simple ternary operator [duplicate]
var args = {VehicleManipulation:[{
'a:Amount':[Amount],
'a:Comment':[Comment],
'a:Date':[date],
'a:...
0
votes
0
answers
48
views
How to add a key-value pair by conditional? [duplicate]
Consider the following example:
const initObject = { a: 2, b: 3, c: 4 };
let shouldChangeB = false;
const newB = 4
const newObject = {
...initObject,
//shouldChangeB && b: newB - ...
0
votes
0
answers
41
views
Is there a better way to compare two objects that have different keys than what I have wrote here? [duplicate]
Basically I'm trying to compare two objects in javascript that have different key names, but I want to match the values of the the objectToSync with the values of the mainObject. Some of the values ...
0
votes
0
answers
40
views
Omiting undefined computed property in JS object [duplicate]
This is the default behavior of computed properties in JS:
const yourName = 'John';
const resultObject = {
[yourName]: 'Glad you're here, let's celebrate!'
}
The resultObject will be computed to ...
1
vote
0
answers
19
views
Sending in a prop object where some are dependant on a boolean value [duplicate]
I have the following component taking in the prop data.
<Button
data={booleanValue && {
d: 4,
// another 8 key/values
}}
/>
So data value only gets passed in if ...
1
vote
0
answers
18
views
javascript - how to return Json conditionally [duplicate]
Is it possible to change from below
if(true){
return {
...baseData,
email: profile.email,
permissions: "admin",
};
}else{
return {
...baseData,
...
0
votes
0
answers
8
views
typescript: sending an object field conditionally [duplicate]
I am trying to have an optional field on object. If the state variable equals active, I want to have data.fields equal to show. If state does not equal active, I don't want terms to even be part of ...
3823
votes
83
answers
2.5m
views
How do I correctly clone a JavaScript object? [duplicate]
I have an object x. I'd like to copy it as object y, such that changes to y do not modify x. I realized that copying objects derived from built-in JavaScript objects will result in extra, unwanted ...
966
votes
22
answers
1.0m
views
Is it possible to add dynamically named properties to JavaScript object?
In JavaScript, I've created an object like so:
var data = {
'PropertyA': 1,
'PropertyB': 2,
'PropertyC': 3
};
Is it possible to add further properties to this object after its initial ...
120
votes
16
answers
203k
views
Passing props to Material UI styles
Given the Card code as in here. How can I update the card style or any material UI style as from:
const styles = theme => ({
card: {
minWidth: 275,
},
To such follows:
const styles = theme =&...