Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get the first character of a string in javascript

let str = 'John Wick'
let firstChar = str.charAt(0) 
console.log(firstChar); // "J" 
Comment

get first word of string js

let myStr = "Hello World"
let firstWord = myStr.split(" ")[0]
Comment

JavaScript - The first word of a string

const str = "What day of the week is it?";

// 1) the match() method:
str.match(/^w+s/)[0];// => What

// 2) the split() method:
str.split(' ')[0];  // => What

// 3) the slice() method:
str.slice(0, str.indexOf(' ')); // => What
Comment

get the first word of a string javascript

let sentence = "The big brown fox"
let word = sentence.split(" ")[0]

console.log(word) // The
Comment

js get first letter of string

var x = 'some string';
alert(x.charAt(0)); // alerts 's'
Comment

get first word in javascript

let string = "Hello World"

let firstWord = typeof string.split(" ")[0] !== 'undefined' ? string.split(" ")[0] : null; 
Comment

js get words first letter

var str = "Java Script Object Notation";
var matches = str.match(/(w)/g); // ['J','S','O','N']
var acronym = matches.join(''); // JSON

console.log(acronym)
Comment

PREVIOUS NEXT
Code Example
Javascript :: loop through an array in javascript 
Javascript :: JS DOM how to add a class name to any HTML element 
Javascript :: js check if radio button is checked 
Javascript :: import { Application } from "express" 
Javascript :: how to detect account change in metamask 
Javascript :: select add option js 
Javascript :: delay javascript function 
Javascript :: how to get custom attribute value in react 
Javascript :: parseint() js 
Javascript :: multiple transform properties javascript 
Javascript :: how to create infinite loop in javascript 
Javascript :: reactjs get checkbox value 
Javascript :: replace backward slash in javascript 
Javascript :: javascript send post 
Javascript :: install gulp ubuntu 20.04 
Javascript :: PG::DuplicateTable: ERROR: relation already exists 
Javascript :: javascript remove all style values in div 
Javascript :: route parammap subscribe angular 9 
Javascript :: ip regex javascript 
Javascript :: js fizzbuzz 
Javascript :: new date() in javascript 3 days from now 
Javascript :: react hook toggle state 
Javascript :: jquery download image from url 
Javascript :: keypress javascript 
Javascript :: Round off a number to the next multiple of 5 using JavaScript 
Javascript :: shadown reAct native 
Javascript :: UpperCase every first letter in each word in str 
Javascript :: iterate 0 to n using for loop javascript 
Javascript :: get child routes using parent in angular 
Javascript :: livewire progress indicators javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =