Sunday, May 30, 2021
Every JavaScript object has a toString() and a toLocaleString() method defined with it. It is a string representation of the object.
For example if we define a date object like the following:
and we output the console.log(date.toString()) method without any extra code we would get the current date and time automatically
By default the toString() method outputs the long form of the date and time. If we want to output a format that is tied to the current locale of the browser. We can call the toLocaleString() instead. Like the following:
and the output will be like the following:
The toString() method works for arrays as well. Let's say we have an array of countries like the example below:
We can output the toString() method to the console with the following code:
console.log(coutnries.toString());
and you would see the following output.
However, the toLocaleString() method will give you the same result because the method does not perform any special locale functions for you. It only works for the date. In order to out the locale representation for the array you need to write your own custom toLocaleString() method for the array.
For example if we define a date object like the following:
var date = new Date();
and we output the console.log(date.toString()) method without any extra code we would get the current date and time automatically
By default the toString() method outputs the long form of the date and time. If we want to output a format that is tied to the current locale of the browser. We can call the toLocaleString() instead. Like the following:
console.log(date.toLocaleString())
and the output will be like the following:
The toString() method works for arrays as well. Let's say we have an array of countries like the example below:
var countries = new Array("U.S.A","Canada","China");
We can output the toString() method to the console with the following code:
console.log(coutnries.toString());
and you would see the following output.
However, the toLocaleString() method will give you the same result because the method does not perform any special locale functions for you. It only works for the date. In order to out the locale representation for the array you need to write your own custom toLocaleString() method for the array.
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Great information for me, I was searching for this.
ReplyDeleteon-demand food delivery app development company