Skip to content
JackSparrow414
Go back

JavaScript Error Notes (Part 1)

Table of contents

Open Table of contents

Article body

  1. JavaScript’s split() divides a string according to the specified rule; the default separator described here is a comma. To split a number, first convert it to a string. For example:

var a = 1000;

document.write(a.split(”));

The code above produces an error.

You need to convert the value with tostring() before using it.

  1. JavaScript’s replace() replaces content according to a specified rule. It can be used to format numbers with thousands separators. The steps are:

Define the matching regular expression: var reg = /\d{1,3}(?=\d{3})+$)/g;

Insert commas into the number: a.toString().replace(reg,”$&,”);

This formats the number with thousands separators.

  1. To set focus on a particular input, use:

$(“input [name = taxcode]“).focus();


Share this post:

Previous Post
Notes on Java’s static Keyword
Next Post
Oracle IN and EXISTS: Query Notes

Comments

Questions, corrections, and experiences are welcome. Sign in with GitHub to comment; both language versions share this discussion.

Comments are available on the live site only.