How can I stop loop when the first time if condition is true?
<p id="numb"></p>
And here is my code javascript, Where i did mistake? i want that when the condition is true the loop stops and don't check other variants?
function round (number) {
var str = number.replace(/[, .]/g, "");
var numb = parseInt(str);
var point = {
"T": Math.pow(10, 12),
"B": Math.pow(10, 9),
"M": Math.pow(10, 6),
"K": Math.pow(10, 3)
};
Object.keys(point).forEach(function (key) {
var pNumb = point[key];
// console.log(pNumb);
// console.log(key);
if (pNumb < numb) {
var letter = key;
console.log(letter);
var z = numb / pNumb;
if (numb % pNumb !== 0) {
document.getElementById("numb").innerHTML = z.toFixed(1) + letter;
} else {
document.getElementById("numb").innerHTML = z + letter;
}
return false;
}
});
}
round("665,421,000")