destruct_objts_dt Flashcards
create a func that accepts a list. the func should pull items from the list which have a specified number of characters and
append the item to a new list. Then,return the new list.
function friend(friends){ var realFriends = []; for(friends[i]= 0; i < friends.length; i++) if ( friends[ i ].length === 4 ) realFriends.push ( friends[ i ]) return realFriends
How can I get a obj. method. to return selected items from an array (from inside an obj) and destruct said items into berries? (return multiple (berried) values in a func) NOTE: func is nested
- order: function (starterIndex, mainIndex) {
return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]];}, - const [berry1, berry2] = obj.func(userInpu1, userInput2)
How can I unpack array items from an object and berry them at the same time?
What about if i wanna skip an item?
const [item1,item2] = obj.keyname
if I wanna skip, simply put a comma between the items in the berried array
unpack multiple array items into berries at same time:
unpack multiple array items into berries at same time:
create a berried array with muliple items. 2. create another array with berry names, replacing each item. The catch: write the array backwards, using the same berry name in the first array.
a = [,2,3,1]
[x,y,z] = a
How can i destruct a nested array: let arr = [4,2,[1,2]]
write it back wards. (i can skip items by writing a comma)
const [i, , [t,g]] = arr
for unknown arrays which i dont know the length, how do i set default values to items that may
not exist?
const [p = 1, q = 1, r = 1] = [8,9] (r is defaulted to 1, the others stay as 8 and 9)
to destruct objs we use {} braces. So , how can I destruct and berry up keys?
const {keyName, keyName1, etc…} = objName
Say that i destructed and berried up some keys. How can I change the berry names if i want?
create another berry-dict; put the original name followed by a colon, and then write the new name. after all the entries, put the equals sign and then the objName
How can i create a default key within an Obj. And, how can I change the name of a key if I want?
const { newKey = [ ], updatedKeyName: renamedKey} = obj
How can i over ride global berries and reassign them
to keys within an obj with the same berry-name?
put curly braces on the left side. Inside go al the berries. Then put the equal sign and the object name.
Next: wrap the entire expression in Evanders
How can I extract and berry-up objects within an object?
start with const. Then put curlies. The 1st nested object comes next. Then put a colon. Then write name of any other secondary nested objects, separated by a comma. then equals primary obj. I keep in mind that the primary obj. has been berried up beforehand.
Can I pass an object as a param in an object method? what would the method look like?
yes. I can pass the keys as parameters. The obj method may look something like this: methName: function (par, par1, par2) { CL( ${this.par[ par index ]}, ${this.par1[ par1 index]} etc )
Note: I call it from out side: MainObjName.method({ put entire dictionary here })
Note: dictionary names must match the param names in the method
Note: i can even set defaults in the params: par = ‘value’
How do I add items to an array: the old way and the new way?
old way: beryup a new array; add the new items and then add the original array items like:
original[ 0 ], original[ 1 ]: berry = [ 1, 2, 3, original[0 ] ]
new way: berry = [1, 2, . . .originalArray]
What prints when I print: CL(. . .myArray)
it unpacks array without evanders
How can i revise an existing property (which contains an array) with new values? (w/o changing original property)
const newProp = [. . .MainObj.propToUpdate, ‘ newValue’ ]