Javascript: Convert string to object.

Source: Internet
Author: User
Javascript type conversion,
String to numeric: parseint ();
Converts a string to a floating point decimal point: parsefloat ();

During JSON data processing, the application needs to convert the string type to the object type.
Although string itself belongs to the object type, it can be used directly in theoretical classes.

However, in actual operations, it is unfortunate that it does not work.
No way. JSON data can be processed correctly only when the string type is converted to the object type.

// String convert to object function
// The string is forcibly converted to the object type
// String to object type
// The JSON parameter is a JSON string, which must be converted before JSON data can be correctly processed
VaR stringtoobject = function (JSON ){
Return eval ("(" + JSON + ")");
}

-- Use JavaScript code to implement zero padding,
-- For example, pad (125, 5) => 00125 /* Simple persistent Storage Method */
Function pad (Num, n ){
VaR Len = num. tostring (). length;
While (LEN <n ){
Num = "0" + num;
Len ++;
}
Return num;
}

--

-- Disable firebug

I believe no one knows what firebug is, but sometimes our bad code doesn't want our peers to easily use F12. So what should we do?

Here is a tricky way to help you achieve this.

If (window. Console & window. Console. firebug ){
Document. Body. innerhtml = '';
}

If you still don't think it's safe, you cannot even use F12.

Document. onkeydown = function (e ){
If (123 = (E | |{}). keycode) return false;
}

Oh, no one has read our code!
--
The demand is always reasonable and strange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.