- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it possible to display substring from object entries in JavaScript?
Yes, you can use Object.fromEntries() along with substr(). Under substr(), mention the index from where to begin the substring and the length.
Example
const originalString = { "John 21 2010" :1010, "John 24 2012" :1011, "John 22 2014" :1012, "John 22 2016" :1013, } const result = Object.fromEntries(Object.entries(originalString). map(([k, objectValue])=> [k.substr(0, k.length-5), objectValue])); console.log(result)
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo41.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo41.js { 'John 21': 1010, 'John 24': 1011, 'John 22': 1013 }
- Related Articles
- Is it possible to use pyplot without DISPLAY?
- Split array entries to form object in JavaScript
- Is it possible to use MongoDB to query for entries that have a particular value in a field in an object in an array?
- Retrieving object's entries in order with JavaScript?
- Is it possible to change the HTML content in JavaScript?
- Is it possible to change directory by using File object in Java?
- Is it possible to write to MongoDB console in JavaScript execution?
- Is it possible to select text boxes with JavaScript?
- Is it possible to create a new data type in JavaScript?
- Is it possible to de-structure to already-declared variables? In JavaScript?
- Is it possible to write data to file using only JavaScript?
- Is it possible to have JavaScript split() start at index 1?
- How is it possible in MySQL to find the location of the first occurrence of a substring in a string?
- Display substring in MySQL if the string is less than a specific length or display a custom message if it is more?
- Is it possible to extract petroleum from under the sea bed?

Advertisements