Home >Web Front-end >JS Tutorial >JavaScript method to convert a string into a character encoding list_javascript skills

JavaScript method to convert a string into a character encoding list_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:08:281158browse

The example in this article describes how JavaScript converts a string into a character encoding list. Share it with everyone for your reference. The details are as follows:

JavaScript converts the string into a character encoding list, for example, foo is converted to [112,111,111]

Method 1: JavaScript 1.6

Array.map('foo', function(x) { return String.charCodeAt(x) })
// is [112,111,111]

Method 2: JavaScript 1.7

[ String.charCodeAt(x) for each ( x in 'foo' ) ]
// is [112,111,111]

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn