- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 01:48 AM
Hi,
My question is whether the JavaScript Object - Key beginning with number is allowed?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 02:23 AM
@Prathyusha G Tested this with a background script and key beginning with a number is allowed.
Here is the script you can run on your instance to verify.
var javaScriptObj = {123:456}
var javaScriptObj1 = {'123':'OneTwoThree'}
var javaScriptObj2 = {'123Number':'Number and letters'}
gs.print(javaScriptObj[123]);
gs.print(javaScriptObj1['123']);
gs.print(javaScriptObj2['123Number']);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 02:23 AM
@Prathyusha G Tested this with a background script and key beginning with a number is allowed.
Here is the script you can run on your instance to verify.
var javaScriptObj = {123:456}
var javaScriptObj1 = {'123':'OneTwoThree'}
var javaScriptObj2 = {'123Number':'Number and letters'}
gs.print(javaScriptObj[123]);
gs.print(javaScriptObj1['123']);
gs.print(javaScriptObj2['123Number']);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 03:05 AM
Thank you Sandeep, its working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 05:27 AM
Here is what ECMAScript specification says:
A property key is either a String or a Symbol. All Strings and Symbols, including the empty String, are valid as property keys.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/