

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Is it possible to use pyplot without DISPLAY?
- Is it possible to make a nested object immutable using Object.freeze() in JavaScript?
- Split array entries to form object in JavaScript
- Is it possible to select text boxes with JavaScript?
- Is it possible to change directory by using File object in Java?
- Is it possible to change the HTML content 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?
- Is it possible to write to MongoDB console in JavaScript execution?
- 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 have JavaScript split() start at index 1?
- Retrieving object's entries in order with JavaScript?
- Is it possible to change the value of the function parameter in JavaScript?
- Is it possible to exclude subclasses from the results displayed in backoffice in SAP?
- Is it possible to style HTML5 audio tag?
Advertisements