Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript string remove a character at position X and add to start

If I have a string and a number:

var str='Thisisabigstring';
var numb=7;

I'm trying to remove the character at position 'numb' from the string and then put it at the beginning of the string.

Trying for output like:

'aThisisbigstring';

How can I do this with javascript/jquery?

like image 509
David19801 Avatar asked Sep 16 '26 04:09

David19801


1 Answers

var str = "Thisisabigstring";
var numb=7;
var c = str.charAt(numb);
str = c + str.substr(0, numb) + str.substr(numb + 1);
like image 78
sjngm Avatar answered Sep 17 '26 18:09

sjngm