我从页面上拿到a,200 b,300 c,400 a,100 这样四组信息。我怎么建一个数组 放 他们,然后循环 得到新数组 a,300 b,300 c,400
解决方案 »
- WdatePicker 的使用,怎样去除快速选择这一项,会的进来下
- 在js中,如何把xmldom对象转化成字符串形式
- 请教图片怎么自适应浏览器大小
- 关于javascript嵌套循环的效率问题,请高手来看看!!!!
- 请各位大侠帮忙:在javascrit中读取word文档内容的问题!
- 请教:Javascript中变量名可否由其它变量替代?
- 关于两个日期间隔月份数的问题
- >>>怎么让一个网页显示30秒后自动关闭?
- IE5.0和IE5.5中的問題,急!
- 关于用alert("信息!")弹出的对话框?
- js里的问题 求解啊
- ext探讨:可编辑grid里能根据数据类型的不同自动变换用下拉列表、日期选择、单选、多选和文本输入等的编辑方式吗?
<script type="text/javascript">
function Hashtable() {
this._hashValue= new Object();
this._iCount= 0;
} Hashtable.prototype.add = function(strKey, value) {
if(typeof(strKey) == "string"){
if(this.contain(strKey)){//这段修改过,为了满足你的需求
this._hashValue[strKey]= typeof(value) != "undefined"? value+this._hashValue[strKey] : null;
}else
{
this._hashValue[strKey]= typeof(value) != "undefined"? value: null;
this._iCount++;
}
return true;
}
else
throw "hash key not allow null!";
} Hashtable.prototype.get = function(key) {
if (typeof(key)== "string" && this._hashValue[key] != typeof('undefined')) {
return this._hashValue[key];
}
if(typeof(key) == "number")
return this._getCellByIndex(key);
else
throw "hash value not allow null!"; return null;
} Hashtable.prototype.contain = function(key) {
return this.get(key) != null;
} Hashtable.prototype.findKey = function(iIndex) {
if(typeof(iIndex) == "number")
return this._getCellByIndex(iIndex, false);
else
throw "find key parameter must be a number!";
} Hashtable.prototype.count = function () {
return this._iCount;
}
Hashtable.prototype._getCellByIndex = function(iIndex, bIsGetValue) {
var i = 0;
if(bIsGetValue == null) bIsGetValue = true;
for(var key in this._hashValue) {
if(i == iIndex) {
return bIsGetValue ? this._hashValue[key] : key;
}
i++;
}
return null;
} Hashtable.prototype.remove = function(key) {
for(var strKey in this._hashValue) {
if(key == strKey)
{
deletethis._hashValue[key];
this._iCount--;
}
}
} Hashtable.prototype.clear = function () {
for (var key in this._hashValue) {
delete this._hashValue[key];
}
this._iCount = 0;
}
</script>
<script type="text/javascript">
var hash=new Hashtable();//简单写了下
hash.add("a",1);
hash.add("b",3);
hash.add("c",13);
hash.add("c",6);
hash.add("a",7);
var v=[];
for(var i=0;i<hash.count();i++){
v.push(hash.findKey(i)+","+hash._getCellByIndex(i));
}
alert(v.join(" "));
</script>
this['甲'] = j;
this['乙'] = y;
this['丙'] = b;
}var objs1 = new Objs(100, 200, 300);var objs2 = new Objs(200, 200, 300);for(var i in objs2) {
alert(i + ':' + objs2[i]);
}
<script type="text/javascript">
var suy = "a:200,b:300,c:400,a:100";
var arr = suy.split(",");
var obj = {};
for(var i=0, l = arr.length; i < l; ++i)
{
var h = arr[i].split(":");
obj[h[0]] = (obj[h[0]]||0) + h[1]*1;
}
for (var i in obj)
{
document.write(i,":",obj[i]," ");
}
</script>
for(var i=1;i<arr.length;i++){
var biaoj=false;
for(var j=0;j<i;j++){
if(arr[j].key==arr[i].key){
arr[j].val==arr[j].concat(arr[i].val);
arr.splice(i,1);
}}}大概这个意思吧...有点不好想,另外 splice貌似低级别ie不支持