20190116

Table of Content

Javascript

// forEach
arr.forEach((num, index) => {
  return (arr[index] = num * 2);
});
// map
var array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]

Vuejs

Style scoped

V-btn div pattern

<v-layout>
  <div>
    <v-btn><v-icon>delete</v-icon></v-btn>
  </div>
</v-layout>

<style>
  button {
    margin: 0;
  }
</style>

@Click

<v-btn @click="testA()" icon flat><v-icon>delete</v-icon></v-btn>
<v-btn @click="testB" icon flat><v-icon>delete</v-icon></v-btn>
<v-btn @click="testC(index, $event)" icon flat><v-icon>delete</v-icon></v-btn>

<script>
  {
      methods: {
          testA: function(a) {
          console.log(a) // expected output is undefined
          },
          testB: function(a) {
          console.log(a); // expected output is event
          },
          testC: function(index, event){

          }
      }
  }
</script>

Javascript

Array to Mp

var arr = [
  { key: "foo", val: "bar" },
  { key: "hello", val: "world" }
];

var result = arr.reduce(function(map, obj) {
  map[obj.key] = obj.val;
  return map;
}, {});

console.log(result);

Important for ES6

// if find object

const index = myArray.indexOf(targetObject); // don't
const indexOfStevie = myArray.findIndex(i => i.hello === "stevie"); // do
Today I Learned