Create new JSON entries conditionally
var obj = {
title: "hello"
};
var upperCase = true;
var newObj = {
...obj,
...(upperCase && {
title: "HELLO"
})
};
var obj = {
title: "hello"
};
var upperCase = true;
var newObj = {
...obj,
...(upperCase && {
title: "HELLO"
})
};
var item = {
id: "1",
title: "Something",
price: "100"
};
const { id, ...itemDetails } = item;
//id -> 1
// itemDetails -> {title:"Something", price:"100"}
var map = new Map();
[...map].forEach(() => {});
//min - inclusive, max - exclusive
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
//random integer
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}