JavaScript Tips

JavaScript Tips

Refresh Page


Map with JavaScript

JavaScript doesn’t have Map like Java.
But we can use Array like Map.

var map = new Object();   // new Array() is also fine.
map["A"] = 1;
map["K"] = 2;
map["B"] = 3;
map[1] = "Acchan";

Convert char to number

We have 2 choices, integer or float
Use parseInt or parseFloat

var num = parseInt('5');
var num2 = parseFloat('5.1');

Whether value is number or not isNaN

Use isNaN

var val = 5;
isNaN(val);  // true