What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-10-08 23:24:06
how to convert an array into an object using javascript
const names = ['Alex', 'Bob', 'Johny', 'Atta']; // convert array to th object const obj = Object.assign({}, names); // print object console.log(obj); // {0: "Alex", 1: "Bob", 2: "Johny", 3: "Atta"} Add solution -
Javascript 2021-10-05 19:50:03
javascript clone object
var student = {name: "Rahul", age: "16", hobby: "football"}; //using ES6 var studentCopy1 = Object.assign({}, student); //using spread syntax var studentCopy2 = {...student}; //Fast cloning with data loss var studentCopy3 =... Add solution -
Javascript 2021-10-01 16:17:03
js string to charcode array
const string = 'hi there'; const usingSplit = string.split(''); const usingSpread = [...string]; const usingArrayFrom = Array.from(string); const usingObjectAssign = Object.assign([], string); // Result // [ 'h', 'i', ' ', 't', 'h', 'e', '... Add solution -
Javascript 2021-09-28 11:33:04
behaviorsubject in angular 10
@Injectable() export class TodoService { private _todos = new BehaviorSubject<Todo[]>([]); private baseUrl = 'https://56e05c3213da80110013eba3.mockapi.io/api'; private dataStore: { todos: Todo[] } = { todos: [] }; readonly todos = this._todo... Add solution -
Javascript 2021-09-24 17:58:02
Updating an object with setState in React
this.setState(prevState => { let jasper = Object.assign({}, prevState.jasper); // creating copy of state variable jasper jasper.name = 'someothername'; // update the name property, assign a new value return {... Add solution -
Javascript 2021-09-22 19:11:02
clone object in js
var student = {name: "Rahul", age: "16", hobby: "football"}; //using ES6 var studentCopy1 = Object.assign({}, student); //using spread syntax var studentCopy2 = {...student}; //Fast cloning with data loss var studentCopy3 =... Add solution -
Javascript 2021-09-20 03:29:05
convert string to char array javascript
const string = 'hi there'; const usingSplit = string.split(''); const usingSpread = [...string]; const usingArrayFrom = Array.from(string); const usingObjectAssign = Object.assign([], string); // Result // [ 'h', 'i', ' ', 't', 'h', 'e', '... Add solution -
Javascript 2021-09-18 17:40:02
clone javascript object
var student = {name: "Rahul", age: "16", hobby: "football"}; //using ES6 var studentCopy1 = Object.assign({}, student); //using spread syntax var studentCopy2 = {...student}; //Fast cloning with data loss var studentCopy3 =... Add solution -
Javascript 2021-09-18 07:05:02
how to add two attay into object in javascript
var keys = ['foo', 'bar', 'baz']; var values = [11, 22, 33] var result = Object.assign.apply({}, keys.map( (v, i) => ( {[v]: values[i]} ) ) ); console.log(result); //returns {"foo": 11, "bar": 22, "baz": 33} Add solution