javascript Array functions
Některé funkce pracující s polem v JavaScriptu
var myArray = []; // smazat obsah, nebo inicializovat nove pole
concat([item1[, item2[, . . . [, itemN]]]])
concat([string2[, string3[, . . . [, stringN]]]])
/* spoji stringy nebo pole a vraci novy string nebo pole */
join(separator)
/* vrati v string spojene itemy poli oddelene separatorem*/
push([item1 [item2 [. . . [itemN ]]]])
/* prida na konec pole novy item a vraci delku pole*/
pop()
/* odebere posledni element z pole a vrati jeho hodnotu*/
reverse()
/*vraci obracene poradi itemu pole*/
shift()
/* odebere prvni item z pole a vrati jej*/
slice(start, [end])
/* varaci cast pole*/
var numArray = new Array(3,2,5,9);
var newNumArray = numArray.slice(1,3); // 2,5
sort() // string
sort(sortFunction)
/* setridi pole cisel od nejvetsiho - descending */
sort(function(a, b){return b-a})
/* setridi od nejmensiho cisla - ascendant*/
sort(function(a, b){return a-b})
splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
/* odebere element z pole, popripade vlozi novy a vrati odebrany element*/
var numArray = new Array(3,2,5,9);
var newNumArray = numArray.splice(1,1); // 3,5,9
unshift([item1[, item2 [, . . . [, itemN]]]])
/* prida na pocatek item, ktery je parametrem funkce */
var myA = new Array(10,11,12);
myA.unshift(1); // 1,10,11,12
77LW NO topic_id
AD
Další témata ....(Topics)
Textarea selection - získání pozice karety kurzoru.
// FOR Gecko Browser selectionStart / selectionEnd selection length
function getPos(){
if (typeof document.getElementById('idTextarea').selectionStart != 'undefined') {
var nPosCursor = document.getElementById('idTextarea').selectionStart;
var nEndPos = document.getElementById('idTextarea').selectionEnd;
return nPosCursor;
}
return 0; // or -1
}
// source by javascript-array.com/guides/javascript_faq/
//Internet Explorer 4+, Mozilla/Gecko/Firefox
function getCaretPos(obj)
{
obj.focus();
if(obj.selectionStart) return obj.selectionStart; //Gecko
else if (document.selection) //Internet Explorer
{
var sel = document.selection.createRange();
var clone = sel.duplicate();
sel.collapse(true);
clone.moveToElementText(obj);
clone.setEndPoint('EndToEnd', sel);
return clone.text.length;
}
return 0;
}
(function () {
String.prototype.isString = true;
String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, "") };
String.prototype.endsWith = function (a) { return this.substr(this.length - a.length) == a };
String.prototype.startsWith = function (a) { return this.substr(0, a.length) == a };
})();
Testování regulárních výrazů - regex
https://regex101.com/
Je možno zadat příchozí adresu a nechat jí upravit, pak znovu nechat projít
Zadá se adresa //bla.bl?query_string=testovany_string
Do velkého pole se zadají
RewriteCond
RewriteRule
a klikne se na TEST
https://htaccess.madewithlove.be/
Přesměrování stránek
https://www.sslmentor.cz/napoveda/presmerovani-https-pomoci-htaccess
Easily check status codes, response headers, and redirect chains.
Kontrola jak probíhá přesměrování s jednotlivými hlášeními - 301, 200, 404 atd.
https://httpstatus.io/
https://regex101.com/
Je možno zadat příchozí adresu a nechat jí upravit, pak znovu nechat projít
Zadá se adresa //bla.bl?query_string=testovany_string
Do velkého pole se zadají
RewriteCond
RewriteRule
a klikne se na TEST
https://htaccess.madewithlove.be/
Přesměrování stránek
https://www.sslmentor.cz/napoveda/presmerovani-https-pomoci-htaccess
Easily check status codes, response headers, and redirect chains.
Kontrola jak probíhá přesměrování s jednotlivými hlášeními - 301, 200, 404 atd.
https://httpstatus.io/
HTTP to HTTPS
# only one RewriteEngine On can be used in htaccess!!!!!!!!!!!!!!
RewriteEngine On
# all redirection HTTP -> HTTPS
# HTTPS off / if start with http.....
# off equality !=on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
example.com to www.example.com
# redirection no www -> https://www.
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Change sitemap.txt to sitemap.php if url //domain.com/sitemap.txt
# //domain.com/sitemap.txt open sitemap.php
# in sitemap.php is function what return list of address
RewriteRule ^sitemap\.txt$ sitemap.php [L]
RewriteRule ^sitemap$ sitemap.php [L]
Remove www. before subdomain name
www.subdomain.example.comto
subdomain.example.com
RewriteCond %{HTTP_HOST} (^|\.)(www\.)([^\.]*)\.example\.com$ [NC]
RewriteRule (.*) https://%3.example.com/$1 [R=301,QSA,L]
Remove dust before subdomain.example.com
# www.bla.www.m.bla.subdomain.example.com to subdomain.example.com
RewriteCond %{HTTP_HOST} (.*)(subdomain.example.com$) [NC]
RewriteRule (.*) https://subdomain.example.com/$1 [R=301,QSA,L]
Remove only one www. before domain name
# redirection www. -> https://
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Editace: 30.1.2021 - 20:38
Počet článků v kategorii: 77
Url:javascript-array-functions