Fix NVM Keeps Forgeting Node Version in New Terminal Session on OSX

I’m installing NVM on OSX but apparently NVM not saving my config, so after installing latest version of node.js and switch to it in new terminal session or after restarting the system, NVM still using old version of node.js.

And follow this link to fix this issue. 😀

Change Vue.js Default Template Tags

As a Django developer I get used to use tag “{{” and “}}” in my template, but when I’m trying to use Vue.js in my project I have to change Vue’s default tags, because Django template and Vue.js has the same tags “{{” and “}}” for binding variable data in html template.

Here is how to change default Vue.js tags

Vue.config.delimiters = ["[[", "]]"];

Now you can using “[[” and “]]” as your Vue.js tags in your project.
FYI you can replace with wathever you want for Vue tags delimiter, but I get used to use double square braces. 😀


Get Particular Object Property Within Javascript Array

I have some object within javascript array and I need to get all data only the name or whatever property inside the object. Usually I iterate entire array and append selected property into new empty array. Below is the code example.

var myList = [{name: 'foo', age: 21}, {name: 'bar', age: 15}, {name: 'john', age: 29}]
var listName = [];
for (var i = 0; i < myList.length; i++) {
console.log(listName); // [ 'foo', 'bar', 'john' ]

And code below is the alternative using map.

var myList = [{name: 'foo', age: 21}, {name: 'bar', age: 15}, {name: 'john', age: 29}];
var listName ={
console.log(listName); // // [ 'foo', 'bar', 'john' ]


Sum Array of Integer in Javascript with Reduce

Alternative code to sum up list of integer in Javascript.

var totalArray = [1, 3, 5].reduce(function(prev, current) {
    return prev + current;
console.log(totalArray); // 9

Code above equivalent with.

var arrayNumber = [1, 3, 5];
var totalArray = 0;
for (var i = 0; i < arrayNumber.length; i++) {
    totalArray += arrayNumber[i];
console.log(totalArray); // 9

I don’t know about performance comparison, soo let you test then and quite similar with python reduce, eh? 😀


Merge 2 or More Array in Javascript

Here is code snippet to merge 2 or more array in javascript.

var arr1 = ["A", "B", "Z"];
var arr2 = ["X"];
var arr3 = [10];

var mergedArray = arr1.concat(arr2).concat(arr3);
console.log(mergedArray); // ["A", "B", "C", "X", 10]


Get URL Parameter in Javascript

Here is code snippet the hackish way to get url parameter in javascript, because AFAIK javascript has no built in method to get url parameter directly.

function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(||[,""])[1].replace(/\+/g, '%20'))||null


var name = getURLParameter("name");
console.log(name); // john