Is there a way to extract only the titles from this JSON array? (using JavaScript/discord.js)

How can I extract the "title" values from this JSON array using JavaScript? I need to retrieve all the "title"s and store them in a new array like shown below:

array(
`hey title1`,
`hey title2`,
...
)

I am unsure of the number of titles we will receive, but I believe it can be achieved using a for loop.

    {
  data: [
    {
      id: '46475273517',
      user_name: 'testtwo',
      title: 'Hello this is my test for the eJx2',
      is_set: true
    },
    {
      id: '46471542013',
      user_name: 'testone',
      title: 'Hello this is my test for the eJx3',
      is_set: false
    },
    {
      id: '46474254233',
      user_name: 'testthree',
      title: 'Hello this is my test for the eJx7',
      is_set: false
    }
  ],
  pagination: {
    cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0'
  }
}

Your assistance is greatly appreciated. Thank you!

Answer №1

const newArray = {
    info: [ { id: '46475273517', username: 'testtwo', heading: 'Hello, this is my first test for the eJx2', checked: true }, { id: '46471542013', username: 'testone', heading: 'Hello, this is my second test for the eJx3', checked: false }, { id: '46474254233', username: 'testthree', heading: 'Hello, this is my third test for the eJx7', checked: false } ], 
    pages: { cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0' } 
} 

const updatedTitles = newArray.info.map((item) => {
        return {
           identity: item.id,
           content: item.heading
        }
    })

This is a basic example where I have included the identity property to identify each title.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Laravel's Collection to Retrieve an Array Containing Objects

I am attempting to retrieve an array of objects with my Laravel collection by using this code snippet: /** * View a user's chat rooms. * * return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory&bsol ...

Why am I unable to retrieve the property from the JSON file?

Below is the provided JSON data: data = { "company_name": "חברה לדוגמה", "audit_period_begin": "01/01/2021", "audit_period_end": "31/12/2021", "reports": [ ...

I am looking to retrieve the body's background color using Regular Expressions

Trying to extract the background color from a CSS string: "body{ background-color: #dfdfdf; } " The color could also be in rgba(120,120,120) format. I am looking for a way to extract that color using regular expressions. I have tried using this patt ...

Creating a Vertical Navbar Dropdown in Bootstrap 3.0 Without Appending to the Last List Item Only

Currently, I'm in the process of creating a panel layout that features an elegant vertical navbar. Although everything seems to be aligned correctly and I've managed to implement a dropdown menu in a vertical layout, it keeps appending to the las ...

Transforming rows into a JSON key/value pair in PostgreSQL is an effective way to organize

In my dataset, I have a simple table with columns labeled Key_1, Key_2, and Value. Each row contains different combinations of Key_1 and Key_2 values. My goal is to transform the rows from this table into a JSON structure that looks like this: { "my ...

Access JSON file without considering any custom comments

Is there a way to extract the JSON data from 'file.json' without including any comments? # Comment01 # Comment02 { "name": "MyName" } I have tried using this code snippet: var fs = require('fs'); var obj; fs.readFile('./file. ...

What is the most effective way to incorporate the DOMContentloaded event listener into the document using nextJS?

I am working on integrating an HTML code snippet into my Next.js project. The snippet includes an external script with a createButton function. <div id="examplebtn"></div> <script type="text/javascript"> //<![ ...

Enhance your data by modifying and updating objects within an array with Mongoose

I am new to the world of MongoDB, specifically using mongoose for defining my schema. I have encountered a roadblock while trying to update or modify a nested array within my schema and could really use some guidance on how to proceed. Let me showcase my ...

What are the steps to downloading a server-generated image with user data from the client using Express?

I am facing a challenge with downloading a server-generated image immediately after it is created. My current approach involves using fetch to send user input data (bypassing HTML forms). Although the image is successfully generated on the server, I am str ...

Using Sinonjs fakeserver to handle numerous ajax requests

I utilize QUnit in combination with sinon. Is there a way to make sinon's fakeserver respond to multiple chained ajax calls triggered from the same method? module('demo', { beforeEach: function(){ this.server = sinon.fakeServer. ...

Comparing JSON strings

In the midst of a C++ project, I find myself struggling to compare multiple JSON strings that are passed as arguments in a function. The goal is to return a boolean based on their comparison. While using Jsoncpp for this task, I've encountered challen ...

Establish a React component to observe socket.io

I am currently looking for the best way to connect my React component with socket.io in order to listen to events. My current approach involves including the following HTML code: <script src="socket.io/socket.io.js"></script> and then initial ...

Making a cross-domain request with jQuery's AJAX function

I am struggling to execute an ajax request using jQuery from my local setup. $.ajax({ url: requestURL, dataType: "json", timeout: 120000, success: function(data){ // do something }, error: func ...

Retrieving data in JSON format from an API and converting it into a more usable JSON format using Flask

How can I convert data from JSON format into a web application using Flask to populate values in HTML? Here is the code in spec_player.html: {% for p in posts: %} <p>{{p.first_name}}</p> {% endfor %} This method works (main.py): posts = ...

Can I deactivate JavaScript on my website directly from my server settings?

I'm currently attempting to link my Android application to a PHP script hosted on a free server. However, when my app tries to access the page, I receive an HTML message stating that JavaScript is disabled and needs to be enabled in order to view the ...

developing a dropdown menu feature

I'm struggling with a small issue related to my drop-down menu function. My goal is to hide the visibility of a menu tab after it has been clicked for the second time. Below is the code snippet I've been working on: HTML:- <nav class="clea ...

Enhance your MongoDB with the power of JQuery and ExpressJS combined with the magic

I've successfully implemented a delete function using type: 'DELETE', and now I'm attempting to create an UPDATE function. However, I'm unsure if I'm approaching this correctly. Here's the code I've written so far: ...

Has anybody successfully implemented the danfojs-node package on an Apple M1 chip?

I encountered an issue when trying to use danfojs-node on a Mac with an M1 chip - it kept crashing due to TensorFlow. I'm curious if anyone has managed to successfully integrate the npm package from this link (https://www.npmjs.com/package/danfojs-nod ...

What is the best way to incorporate the "child_process" node module into an Angular application?

Trying to execute a shell script in my Angular application has been quite the challenge. I came across the "child process" node library that might be able to help me with this task. However, every attempt to import the library led me to the error message: ...

How to eliminate the unnecessary gap between rows in a Vue div displayed as a grid

I have recently started working with Vue and in my current project, I encountered a challenge where I needed to display 2 players in each row within a div. To achieve this, I utilized the display: grid; CSS property on the playerDiv id. However, I am facin ...