Site Notice

hello, world

Difference between revisions of "User:机智的小鱼君/common.js"

From Project-EPB Commons
Line 19: Line 19:
 
       }
 
       }
  
var a = ['this is 1','this is 2','this is 3'];
+
var jsona = {
alert( 'now random: '+ getArrItem(a,1) );
+
  text: ['this is 1','this is 2','this is 3'],
 +
  p: '1#3'
 +
},
 +
    geta = jsona.text;
 +
$('#firstHeading').after( 'now random: '+ getArrItem(jsona.text,1) );

Revision as of 16:47, 6 November 2019

mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2');

      function getArrItem(arr, num) {
          var temp_array = new Array();
          for (var index in arr) {
              temp_array.push(arr[index]);
          }
          var return_array = new Array();
          for (var i = 0; i < num; i++) {
              if (temp_array.length > 0) {
                  var arrIndex = Math.floor(Math.random() * temp_array.length);
                  return_array[i] = temp_array[arrIndex];
                  temp_array.splice(arrIndex, 1);
              } else {
                  break;
              }
          }
          return return_array;
      }

var jsona = {
  text: ['this is 1','this is 2','this is 3'],
  p: '1#3'
},
    geta = jsona.text;
$('#firstHeading').after( 'now random: '+ getArrItem(jsona.text,1) );