I have an array containing some fields
like this
ctl00_ctl00_cphBody_bodycph_content_rdo_SID_25_SortOrder_17 ctl00_ctl00_cphBody_bodycph_content_rdo_SID_25_SortOrder_18 ctl00_ctl00_cphBody_bodycph_content_rdo_SID_25_SortOrder_19
I want to create a new array or manipulate this array so that it contains only
sid = {25,26,27}
from
_SID_25 _SID_26 _SID_27
where sid will be my array containing sid extracted from the above pattern array _SID_
_SID_
I need to do this in jquery or javascript
use jquery map + regexp
var arr= ['tl00_ctl00_cphBody_bodycph_content_rdo_SID_25_SortOrder_17', 'ctl00_ctl00_cphBody_bodycph_content_rdo_SID_26_SortOrder_18', 'ctl00_ctl00_cphBody_bodycph_content_rdo_SID_27_SortOrder_19'] var out = $(arr).map(function(){ return this.match(/SID_(.*?)_/)[1]; });
out should be an array of values.
(provided that all values ββin the array match the pattern)
I would use regex here
var sid = [] var matches = "ctl00_ctl00_cphBody_bodycph_content_rdo_SID_25_SortOrder_17".match(/_SID_(\d+)/); if(matches) sid.push(parseInt(matches[1]));
, , "", , , , , . "SID_", , , .
:
s = "ctl00_ctl00_cphBody_bodycph_content_rdo_SID_25344_SortOrder_17"
array.push(parseInt(s.split("SID_")[1].split("_")[0]))
array.push(parseInt(s.split("_")[7])
Source: https://habr.com/ru/post/1755921/More articles:pasting text into xterm in GNOME using the gtk clipboard - cHow to make our form (application) run when windows start in C #? - c #Parsing the canonical path using wildcards - c #Is medical imaging a separate programming specialty? - image-processingopenGL spinning with lighting problem - rotationHow to specify inline css style in java-mail? Or How to include CSS in java mail? - javawhy am I still not getting an empty array? - arraysLanguage level thread - javajQuery how to make synchronous animation? - javascriptHow to limit a line if it is more than necessary? - stringAll Articles