Tips for extracting a segment from an Object within an Array

I am looking to extract the datetime value from each element in the array below:

[<time pubdate class="dt-updated" datetime="2015-07-09T11:50:32+0000" title="Time posted: 09 Jul 2015, 11:50:32 (UTC)" aria-label="Posted on 09 Jul">09 Jul</time>, <time pubdate class="dt-updated" datetime="2015-06-18T13:59:49+0000" title="Time posted: 18 Jun 2015, 13:59:49 (UTC)" aria-label="Posted on 18 Jun">18 Jun</time>, <time pubdate class="dt-updated" datetime="2015-06-18T12:56:47+0000" title="Time posted: 18 Jun 2015, 12:56:47 (UTC)" aria-label="Posted on 18 Jun">18 Jun</time>, <time pubdate class="dt-updated" datetime="2015-06-18T12:41:42+0000" title="Time posted: 18 Jun 2015, 12:41:42 (UTC)" aria-label="Posted on 18 Jun">18 Jun</time>]

Is there a method for handling this extraction process within a loop that I can utilize? I have not come across a suitable solution yet during my online search...

Answer №1

One way to extract datetime values is by using a regex match like datetime="(.*?)"

If you want to see this method in action, check out the following link: https://regex101.com/r/wE0mZ8/1

By implementing this regex pattern, you can store all datetime values into an array:

var str = '[<time pubdate class="dt-updated" datetime="2015-07-09T11:50:32+0000" title="Time posted: 09 Jul 2015, 11:50:32 (UTC)" aria-label="Posted on 09 Jul">09 Jul</time>, <time pubdate class="dt-updated" datetime="2015-06-18T13:59:49+0000" title="Time posted: 18 Jun 2015, 13:59:49 (UTC)" aria-label="Posted on 18 Jun">18 Jun</time>, <time pubdate class="dt-updated" datetime="2015-06-18T12:56:47+0000" title="Time posted: 18 Jun 2015, 12:56:47 (UTC)" aria-label="Posted on 18 Jun">18 Jun</time>, <time pubdate class="dt-updated" datetime="2015-06-18T12:41:42+0000" title="Time posted: 18 Jun 2015, 12:41:42 (UTC)" aria-label="Posted on 18 Jun">18 Jun</time>]';
var res = str.match(/datetime="(.*?)"/gi); 
alert (res[0]);

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

Enhanced file uploading feature in Firefox 4 using AjaxForm

<form action="upload.aspx" enctype="multipart/form-data" id="ajaxUploadForm" method="post"> <input type="file" name="fileBase" id="fileBase"><input type="submit" value="send" /> </form> $( "#ajaxUploadForm" ).ajaxForm( { iframe: "t ...

Show information retrieved from fetch api

Hi there! I've been trying to fetch data from the Avascan API and display it on my HTML page, but so far, I haven't had any luck. I've experimented with using the Fetch API, JSON, and AJAX methods, but none of them seem to work for me. Do yo ...

How to efficiently deliver a document to a user using the MEAN stack

The express controller code snippet I'm working with involves creating a CSV file and sending it back to the user: // Correct file path and write data var currentDate = new Date(); var storagePath = path.join(__dirname,'../../public/reports/&apo ...

Cursor hovers over button, positioned perfectly in the center

I am facing a challenge with implementing a hover function for a set of buttons on the screen. The goal is to display the mouse pointer at the center of the button upon hovering, rather than the actual position of the cursor being displayed. I have tried u ...

What is the best way to change a List of integers to an array of strings in C#?

Looking for a simple solution to change a List<int> into a string array. Here's what I currently have: var my_list = new List<int>(); my_list.Add(1); my_list.Add(2); my_list.Add(3); string[] my_array = new string[my_list.Count]; for(var ...

Defining the TypeScript interface for the onClick event in ReactJS

If you're looking to dive into React development, the tutorial on reactjs.org is a great place to start. While the tutorial code is in JavaScript, I've been working on converting it to TypeScript. I've successfully translated most of the c ...

Is there a way to limit the rotation of an a-camera in aframe?

One scenario could be enabling rotation around the z-axis within a range of -70 to 70 degrees, or alternatively, preventing rotation around any arbitrary axis. Thank you! ...

Utilizing getStaticProps for Performance Optimization in Next.js

I am currently in the process of setting up a blog using Next.js and GraphCMS. I have an ArticleList component that I want to display on multiple pages, such as my homepage and under each article as a recommendation. Since the article list is sourced from ...

The Angular controller that has been injected into the app is not defined

In an effort to enhance my simple Angular app, I decided to modularize it. I separated the controller into its own file within a dedicated directory. By employing dependency injection, I ensured the controller's availability in the app module. Combini ...

I possess a single input field and I am seeking to have the focus shifted to it upon the activation of a button

Looking to enhance user input with an icon interaction: Clicking the icon should focus on the input Considering a solution for when clicking the icon to trigger focusout A code snippet has been implemented for the first requirement, seeking suggestions ...

Identifying the user's location within the application and dynamically loading various Angular scripts

Currently, I am working on a large-scale web application using Laravel and Angular. In this project, I have integrated various angular modules that come with their own controllers, directives, and views. One challenge I am facing is the need to load diffe ...

What is the proper way to invoke a function that is part of a child component as a property in a React application?

In my app.js file, I have included a unique component called "SigningComponent" with the following code: onSign = () => { this.setState({ route: "home" }); }; registerFunction = () => { this.setState({ route: "registration" }); }; render() { ...

Endless asynchronous loops with setInterval()

My nodejs application requires multiple infinite loops that call asynchronous functions. I was contemplating the following approach: async function process1() { ...perform some asynchronous tasks... } async function process2() { ...perform some as ...

FoxyWeb Requests: Utilizing XMLHttpRequest in Firefox Extensions

While I've come across plenty of examples on how to create xhr requests from Firefox Add-ons, I'm currently exploring the new WebExtensions framework (where require and Components are undefined) and facing an issue with sending a simple XmlHttpRe ...

Frisby.js is looking for a valid JavaScript object, but instead received an undefined value

Struggling to launch a new test using the API testing framework Frisby.js. In my previous tests that didn't involve reading reference files from disk, everything ran smoothly and quickly. The samples provided with Frisby also executed accurately. Thi ...

What is the method to process a JSON path containing a special character like "@"?

I'm attempting to retrieve JSON data from an API with the following structure. My current approach involves using JavaScript. The code snippet I have utilized is displayed below. <p>"stations": [</p> <p id="data"></p> ...

Is there a way to get rid of the tiny black line beside the Instagram icon?

Here is the display on my website This is the code that was used I am struggling to identify the source of the small black "-" line next to the Instagram icon logo. ...

What are some ways I can customize this jQuery :submit selector demonstration?

After reviewing the jQuery example provided here, I am curious about how to adjust the code in order to change the color of a cell only when the value of the submit button within that cell meets certain criteria. For instance: var submitEl = $( ...

Neither setState() nor forceUpdate() trigger the rendering process

I am working with a basic React setup that resembles the following structure: index.js ReactDOM.render(<App />, document.getElementById('root')); App.js export default class App extends Component { constructor(props) { super ...

Identifying instances where the AJAX success function exceeds a 5-second duration and automatically redirecting

Greetings! I have created a script that allows for seamless page transitions using Ajax without reloading the page. While the script functions perfectly, I am seeking to implement a feature that redirects to the requested page if the Ajax request takes lo ...