How can I extract only the initials of 2 characters after spaces? See the code snippet below:
const name = "John Peter Don";
const result = name.match(/\b(\w)/g).join('');
console.log(result)// JPD->> i want only JP
How can I extract only the initials of 2 characters after spaces? See the code snippet below:
const name = "John Peter Don";
const result = name.match(/\b(\w)/g).join('');
console.log(result)// JPD->> i want only JP
To extract the initials from a string using regex, you can use the match()
method to capture all leading capital letters. Once you have these captured letters, you can then combine the first two elements to create the desired output.
var fullName = "John Peter Don";
var nameInitials = fullName.match(/\b[A-Z]/g).slice(0, 2).join("");
console.log(nameInitials);
Following the advice given by Wiktor Stribiżew in the comments
const name = "John Peter Don";
let splitName = name.split(" ");
console.log(splitName[0][0], splitName[1][0]);
console.log("Combined initials: ", splitName[0][0] + splitName[1][0]);
I am configuring routes for my express app and need the following paths: /regions /regions/europe /regions/europe/france /regions/europe/france/paris Currently, I have set up individual route handlers for each path. Is there a more efficient way to ha ...
I have implemented two date inputs in my PHP form: Arrival Date Departure Date Currently, when the Date Icon is selected, it displays the CURRENT DATE AND MONTH. What I am looking for is that when the user selects the Arrival Date first and then the De ...
I am in the process of developing an application that can download a specific number of tweets. For this project, I am utilizing node.js and express() within my server.js file. To retrieve data from the Twitter API, I have set up a route app.get('/ap ...
I am currently utilizing devise within a rails application. I have successfully logged into my rails server (devise) using the following curl command: curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST h ...
Prior to diving into this, I am determined to steer clear of utilizing Jquery for personal reasons that I won't delve into. So please refrain from suggesting it, as that is not the solution I seek. I am currently working on a web page that sends mult ...
I am facing a situation with nested loops for (var key in params) { if (Array.isArray(params[key])) { params[key].every(function(item) { let value = something(item.start, item.end); if (value === item.start || value == item.end) { ...
Is there a way to efficiently load/render large html tables without compromising performance, especially in Internet Explorer? I recently came across a plugin in prototype.js (https://github.com/jbrantly/bigtable/, post: , demo:) that addresses this issue ...
Looking for a handy solution that allows users to either accept or reject a website's cookie policy. I came across an interesting library called cookies-EU-Banner (found at ) which seems to be quite popular. It recognizes when the user clicks on Reje ...
I have a group of div elements arranged side by side with the float:left style as shown below: <div id="container"> <div id=0" style="float:left">> Stuff </div> <div id=1" style="float:left">> Stuff </div> < ...
I'm facing an issue with my Google map. I have a data array that is dynamically returned, and I want to use it to add markers to the map. However, the markers don't work when I pass the data variable to the add_markers() function. It only works i ...
Hey there, currently working on a project using THREE.js and I've run into an issue with my .mouseButtons functionality. var controls = new THREE.OrbitControls( camera, renderer.domElement ); controls.target.set( 0, 25, 0 ); c ...
Looking to update values in rows of a table? Here is an example table: I need to update the title per selected row. After selecting the first row, changing the value works fine. However, when I choose the second row, the issue arises where the value from ...
Imagine this scenario: <input type="text"> The task at hand is to prevent text selection within the <input> field. ...
I have a situation where I have a list with two buttons, and each button triggers the same dropdown content in a sidebar component. The issue is that when I click on one button to open the dropdown, the second button does not move down to make space for it ...
I'm currently working on a project that involves dynamically generating trees using simple cubes for branches and leaves in the early prototype stages. Each tree consists of a hierarchy of cubes nested with rotations and scaling to create the final st ...
Everything was working fine with the form submission until I turned it into a modal using Bootstrap. Now, when the form is rendered in the modal, users can tab and type without any issues. However, if they click on any element within the modal (including t ...
Whenever I go for a run, I have to specify a starting point such as /pis/ ng serve --serve-path /pis/ Even after following these instructions, nothing seems to load. Can anyone lend a hand with setting a starting point in the ng serve process? ...
Here's an example of how I'm initializing a property: this.currentMapObject$ = zip(this.mapObjects$, this.currentMapObjectsIndex$, (mapObjects, index) => mapObjects[index]); I want the value of this.currentMapObject$ to be emitted only ...
* **> const PORT=8000 const express = require('express') const {v4:uuidv4}=require('uuid') const bcrypt =require('bcrypt') const jwt =require('jsonwebtoken') const cors=require('cors') const {MongoClie ...
Looking to dynamically change the HTML5 video tag with each click of an li tag. Here is the current structure: <div class="flexslider"> <ul class="slides"> <li> <video> <source type="video/mp4" src="http://t ...